mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 23:14:13 +01:00
ircd:Ⓜ️ Add parallel get() suite to interface.
This commit is contained in:
parent
47ce9ff839
commit
6885bafc49
3 changed files with 81 additions and 0 deletions
|
@ -45,6 +45,7 @@ struct ircd::m::event::fetch
|
|||
|
||||
using keys = event::keys;
|
||||
using view_closure = std::function<void (const string_view &)>;
|
||||
using views_closure = std::function<void (const vector_view<const string_view> &)>;
|
||||
|
||||
static const opts default_opts;
|
||||
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
|
||||
namespace ircd::m
|
||||
{
|
||||
// Fetch the value for a single property of multiple events in parallel into the closure.
|
||||
uint64_t get(std::nothrow_t, const vector_view<const event::idx> &, const string_view &key, const event::fetch::views_closure &);
|
||||
void get(const vector_view<const event::idx> &, const string_view &key, const event::fetch::views_closure &);
|
||||
|
||||
// Fetch the value for a single property of an event into the closure.
|
||||
bool get(std::nothrow_t, const event::idx &, const string_view &key, const event::fetch::view_closure &);
|
||||
bool get(std::nothrow_t, const event::id &, const string_view &key, const event::fetch::view_closure &);
|
||||
|
|
|
@ -227,3 +227,79 @@ ircd::m::get(std::nothrow_t,
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::get(const vector_view<const event::idx> &event_idx,
|
||||
const string_view &key,
|
||||
const event::fetch::views_closure &closure)
|
||||
{
|
||||
const auto mask
|
||||
{
|
||||
get(std::nothrow, event_idx, key, closure)
|
||||
};
|
||||
|
||||
const auto found
|
||||
{
|
||||
__builtin_popcountl(mask)
|
||||
};
|
||||
|
||||
if(unlikely(found < event_idx.size()))
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"Only %zu/%zu for %s found in database",
|
||||
found,
|
||||
event_idx.size(),
|
||||
key,
|
||||
};
|
||||
}
|
||||
|
||||
uint64_t
|
||||
ircd::m::get(std::nothrow_t,
|
||||
const vector_view<const event::idx> &event_idx,
|
||||
const string_view &key,
|
||||
const event::fetch::views_closure &closure)
|
||||
{
|
||||
const auto &column_idx
|
||||
{
|
||||
json::indexof<event>(key)
|
||||
};
|
||||
|
||||
auto &column
|
||||
{
|
||||
dbs::event_column.at(column_idx)
|
||||
};
|
||||
|
||||
if(unlikely(!column))
|
||||
throw panic
|
||||
{
|
||||
"Parallel fetch not yet supported for key '%s'",
|
||||
key,
|
||||
};
|
||||
|
||||
if(!event_idx.size())
|
||||
return 0;
|
||||
|
||||
static const auto MAX {64UL};
|
||||
const auto &num
|
||||
{
|
||||
std::min(event_idx.size(), MAX)
|
||||
};
|
||||
|
||||
string_view column_key[num];
|
||||
for(uint i(0); i < num; ++i)
|
||||
column_key[i] = byte_view<string_view>
|
||||
{
|
||||
event_idx[i]
|
||||
};
|
||||
|
||||
const vector_view<const string_view> keys
|
||||
{
|
||||
column_key, num
|
||||
};
|
||||
|
||||
return column(keys, std::nothrow, [&closure]
|
||||
(const vector_view<const string_view> &res)
|
||||
{
|
||||
closure(res);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue