mirror of
https://github.com/matrix-construct/construct
synced 2024-06-10 05:58:56 +02:00
ircd:Ⓜ️ Add suite to check if event is cached.
This commit is contained in:
parent
4c5891e354
commit
38920719de
|
@ -26,6 +26,7 @@ namespace ircd::m
|
|||
// [GET]
|
||||
bool exists(const id::event &);
|
||||
bool exists(const id::event &, const bool &good);
|
||||
bool cached(const id::event &);
|
||||
bool good(const id::event &);
|
||||
bool bad(const id::event &);
|
||||
|
||||
|
|
|
@ -55,6 +55,10 @@ struct ircd::m::event::fetch
|
|||
friend const_buffer get(const idx &, const string_view &key, const mutable_buffer &out);
|
||||
friend const_buffer get(const id &, const string_view &key, const mutable_buffer &out);
|
||||
|
||||
friend bool cached(const idx &, const opts & = default_opts);
|
||||
friend bool cached(const id &, const opts &);
|
||||
friend bool cached(const id &);
|
||||
|
||||
friend void prefetch(const idx &, const string_view &key);
|
||||
friend void prefetch(const idx &, const opts & = default_opts);
|
||||
friend void prefetch(const id &, const string_view &key);
|
||||
|
|
|
@ -220,6 +220,57 @@ ircd::m::good(const id::event &event_id)
|
|||
return index(event_id, std::nothrow) != 0;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::cached(const id::event &event_id)
|
||||
{
|
||||
return cached(event_id, event::fetch::default_opts);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::cached(const id::event &event_id,
|
||||
const event::fetch::opts &opts)
|
||||
{
|
||||
if(!db::cached(dbs::event_idx, event_id, opts.gopts))
|
||||
return false;
|
||||
|
||||
const event::idx event_idx
|
||||
{
|
||||
index(event_id, std::nothrow)
|
||||
};
|
||||
|
||||
return event_idx?
|
||||
cached(event_idx, opts.gopts):
|
||||
false;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::cached(const event::idx &event_idx,
|
||||
const event::fetch::opts &opts)
|
||||
{
|
||||
const byte_view<string_view> key
|
||||
{
|
||||
event_idx
|
||||
};
|
||||
|
||||
const auto &select(opts.keys);
|
||||
auto &columns(dbs::event_column);
|
||||
return std::all_of(begin(select), end(select), [&opts, &key, &columns]
|
||||
(const string_view &colname)
|
||||
{
|
||||
const auto &idx
|
||||
{
|
||||
json::indexof<event>(colname)
|
||||
};
|
||||
|
||||
auto &column
|
||||
{
|
||||
columns.at(idx)
|
||||
};
|
||||
|
||||
return db::cached(column, key, opts.gopts);
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::exists(const id::event &event_id,
|
||||
const bool &good)
|
||||
|
|
Loading…
Reference in a new issue