0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-28 11:48:54 +02:00

ircd:Ⓜ️ Use event::keys::selection bitset in event::fetch::opts rather than event::keys.

This commit is contained in:
Jason Volk 2019-01-23 15:36:02 -08:00
parent 2b9e2c850e
commit 92154be55d
5 changed files with 37 additions and 64 deletions

View file

@ -98,23 +98,18 @@ namespace ircd::m
struct ircd::m::event::fetch::opts struct ircd::m::event::fetch::opts
{ {
/// Event property selector /// Event property selector
event::keys keys; event::keys::selection keys;
/// Database get options passthru /// Database get options passthru
db::gopts gopts; db::gopts gopts;
/// Whether to allow querying the event_json to populate the event. A value
/// of true only allows this type of query to be made; a value of false
/// prevents this query from ever being made.
bool query_json {true};
/// Whether to force an attempt at populating the event from event_json /// Whether to force an attempt at populating the event from event_json
/// first, bypassing any decision-making. This is useful if a key selection /// first, bypassing any decision-making. This is useful if a key selection
/// is used which would trigger a row query but the developer wants the /// is used which would trigger a row query but the developer wants the
/// json query anyway. /// json query anyway.
bool query_json_force {false}; bool query_json_force {false};
opts(const event::keys &, const db::gopts & = {}); opts(const event::keys::selection &, const db::gopts & = {});
opts(const db::gopts &, const event::keys & = {}); opts(const db::gopts &, const event::keys::selection & = {});
opts() = default; opts() = default;
}; };

View file

@ -2576,13 +2576,9 @@ ircd::m::user::rooms::for_each(const string_view &membership,
const const
{ {
// Setup the list of event fields to fetch for the closure // Setup the list of event fields to fetch for the closure
static const event::keys keys static const event::keys::include keys
{ {
event::keys::include "state_key", "content",
{
"state_key",
"content",
}
}; };
const m::event::fetch::opts fopts const m::event::fetch::opts fopts

View file

@ -253,13 +253,13 @@ bool
ircd::m::cached(const event::idx &event_idx, ircd::m::cached(const event::idx &event_idx,
const event::fetch::opts &opts) const event::fetch::opts &opts)
{ {
const auto &select(opts.keys);
auto &columns(dbs::event_column);
const byte_view<string_view> &key const byte_view<string_view> &key
{ {
event_idx event_idx
}; };
auto &columns(dbs::event_column);
const event::keys &select(opts.keys);
return std::all_of(begin(select), end(select), [&opts, &key, &columns] return std::all_of(begin(select), end(select), [&opts, &key, &columns]
(const string_view &colname) (const string_view &colname)
{ {
@ -1228,11 +1228,8 @@ void
ircd::m::prefetch(const event::idx &event_idx, ircd::m::prefetch(const event::idx &event_idx,
const event::fetch::opts &opts) const event::fetch::opts &opts)
{ {
const vector_view<const string_view> cols const event::keys keys{opts.keys};
{ const vector_view<const string_view> cols{keys};
opts.keys
};
for(const auto &col : cols) for(const auto &col : cols)
if(col) if(col)
prefetch(event_idx, col); prefetch(event_idx, col);
@ -1624,7 +1621,7 @@ ircd::m::event::fetch::fetch(const event::idx &event_idx,
event_idx && !_json.valid(key(&event_idx))? event_idx && !_json.valid(key(&event_idx))?
key(&event_idx): key(&event_idx):
string_view{}, string_view{},
opts.keys, event::keys{opts.keys},
cell, cell,
opts.gopts opts.gopts
} }
@ -1650,7 +1647,7 @@ ircd::m::event::fetch::fetch(const opts &opts)
{ {
*dbs::events, *dbs::events,
string_view{}, string_view{},
opts.keys, event::keys{opts.keys},
cell, cell,
opts.gopts opts.gopts
} }
@ -1704,21 +1701,18 @@ ircd::m::event::fetch::assign_from_row(const opts &opts,
bool bool
ircd::m::event::fetch::should_seek_json(const opts &opts) ircd::m::event::fetch::should_seek_json(const opts &opts)
{ {
// User never wants to make the event_json query // User always wants to make the event_json query regardless
if(!opts.query_json) // of their keys selection.
return false;
// User always wants to make the event_json query
if(opts.query_json_force) if(opts.query_json_force)
return true; return true;
// User is making specific column queries // If and only if selected keys have direct columns we can return
if(opts.keys.count() < event::size()) // false to seek direct columns. If any other keys are selected we
return false; /// must perform the event_json query instead.
for(size_t i(0); i < opts.keys.size(); ++i)
// User is querying all columns if(opts.keys.test(i))
if(opts.keys.count() == event::size()) if(!dbs::event_column.at(i))
return true; return true;
return false; return false;
} }
@ -1735,7 +1729,7 @@ ircd::m::event::fetch::key(const event::idx *const &event_idx)
// //
ircd::m::event::fetch::opts::opts(const db::gopts &gopts, ircd::m::event::fetch::opts::opts(const db::gopts &gopts,
const event::keys &keys) const event::keys::selection &keys)
:opts :opts
{ {
keys, gopts keys, gopts
@ -1743,7 +1737,7 @@ ircd::m::event::fetch::opts::opts(const db::gopts &gopts,
{ {
} }
ircd::m::event::fetch::opts::opts(const event::keys &keys, ircd::m::event::fetch::opts::opts(const event::keys::selection &keys,
const db::gopts &gopts) const db::gopts &gopts)
:keys{keys} :keys{keys}
,gopts{gopts} ,gopts{gopts}

View file

@ -371,7 +371,7 @@ ircd::m::room::membership(const mutable_buffer &out,
const m::id::user &user_id) const m::id::user &user_id)
const const
{ {
static const event::keys membership_keys static const event::keys::selection membership_keys
{ {
event::keys::include{"membership"} event::keys::include{"membership"}
}; };
@ -405,7 +405,7 @@ const
// is a rare case so both queries are optimized to only seek for their key. // is a rare case so both queries are optimized to only seek for their key.
if(exists && !ret) if(exists && !ret)
{ {
static const event::keys content_membership_keys static const event::keys::selection content_membership_keys
{ {
event::keys::include{"content"} event::keys::include{"content"}
}; };
@ -1640,14 +1640,11 @@ const
} }
// The list of event fields to fetch for the closure // The list of event fields to fetch for the closure
static const event::keys keys static const event::keys::include keys
{ {
event::keys::include "event_id", // Added for any upstack usage (but may be unnecessary).
{ "membership", // Required for membership test.
"event_id", // Added for any upstack usage (but may be unnecessary). "content", // Required because synapse events randomly have no event.membership
"membership", // Required for membership test.
"content", // Required because synapse events randomly have no event.membership
}
}; };
const m::event::fetch::opts fopts const m::event::fetch::opts fopts
@ -1726,15 +1723,12 @@ ircd::m::room::members::for_each(const string_view &membership,
const const
{ {
// Setup the list of event fields to fetch for the closure // Setup the list of event fields to fetch for the closure
static const event::keys keys static const event::keys::include keys
{ {
event::keys::include "event_id",
{ "membership",
"event_id", "state_key",
"membership", "content", // Required because synapse events randomly have no event.membership
"state_key",
"content", // Required because synapse events randomly have no event.membership
}
}; };
// In this case the fetch opts isn't static so it can maintain the // In this case the fetch opts isn't static so it can maintain the
@ -2460,12 +2454,9 @@ bool
ircd::m::room::power::view(const std::function<void (const json::object &)> &closure) ircd::m::room::power::view(const std::function<void (const json::object &)> &closure)
const const
{ {
static const event::keys keys static const event::keys::include keys
{ {
event::keys::include "content",
{
"content",
}
}; };
const m::event::fetch::opts fopts const m::event::fetch::opts fopts

View file

@ -184,12 +184,9 @@ void
ircd::m::rooms::local_summary_chunk(const m::room &room, ircd::m::rooms::local_summary_chunk(const m::room &room,
json::stack::object &obj) json::stack::object &obj)
{ {
static const event::keys keys static const event::keys::include keys
{ {
event::keys::include "content",
{
"content",
}
}; };
const m::event::fetch::opts fopts const m::event::fetch::opts fopts