0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-24 12:58:21 +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
{
/// Event property selector
event::keys keys;
event::keys::selection keys;
/// Database get options passthru
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
/// 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
/// json query anyway.
bool query_json_force {false};
opts(const event::keys &, const db::gopts & = {});
opts(const db::gopts &, const event::keys & = {});
opts(const event::keys::selection &, const db::gopts & = {});
opts(const db::gopts &, const event::keys::selection & = {});
opts() = default;
};

View file

@ -2576,13 +2576,9 @@ ircd::m::user::rooms::for_each(const string_view &membership,
const
{
// 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

View file

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

View file

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

View file

@ -184,12 +184,9 @@ void
ircd::m::rooms::local_summary_chunk(const m::room &room,
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