mirror of
https://github.com/matrix-construct/construct
synced 2024-11-26 08:42:34 +01:00
ircd:Ⓜ️:event: Augment event::horizon interface allowing full column iteration.
This commit is contained in:
parent
2a47c82534
commit
c119c84c2f
3 changed files with 35 additions and 11 deletions
|
@ -27,13 +27,14 @@ class ircd::m::event::horizon
|
||||||
event::id event_id;
|
event::id event_id;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using closure_bool = event::closure_idx_bool;
|
using closure_bool = std::function<bool (const event::id &, const event::idx &)>;
|
||||||
|
|
||||||
bool for_each(const closure_bool &) const;
|
bool for_each(const closure_bool &) const;
|
||||||
bool has(const event::idx &) const;
|
bool has(const event::idx &) const;
|
||||||
size_t count() const;
|
size_t count() const;
|
||||||
|
|
||||||
horizon(const event::id &);
|
horizon(const event::id &);
|
||||||
|
horizon() = default;
|
||||||
|
|
||||||
static bool has(const event::id &);
|
static bool has(const event::id &);
|
||||||
static size_t rebuild();
|
static size_t rebuild();
|
||||||
|
|
|
@ -2588,7 +2588,8 @@ ircd::m::event::horizon::count()
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
size_t ret(0);
|
size_t ret(0);
|
||||||
for_each([&ret](const auto &)
|
for_each([&ret]
|
||||||
|
(const auto &, const auto &)
|
||||||
{
|
{
|
||||||
++ret;
|
++ret;
|
||||||
return true;
|
return true;
|
||||||
|
@ -2602,7 +2603,7 @@ ircd::m::event::horizon::has(const event::idx &event_idx)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
return !for_each([&event_idx]
|
return !for_each([&event_idx]
|
||||||
(const auto &_event_idx)
|
(const auto &, const auto &_event_idx)
|
||||||
{
|
{
|
||||||
// false to break; true to continue.
|
// false to break; true to continue.
|
||||||
return _event_idx == event_idx? false : true;
|
return _event_idx == event_idx? false : true;
|
||||||
|
@ -2613,25 +2614,47 @@ bool
|
||||||
ircd::m::event::horizon::for_each(const closure_bool &closure)
|
ircd::m::event::horizon::for_each(const closure_bool &closure)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
if(!this->event_id)
|
||||||
|
{
|
||||||
|
db::column &column{dbs::event_horizon};
|
||||||
|
for(auto it(column.begin()); it; ++it)
|
||||||
|
{
|
||||||
|
const auto &parts
|
||||||
|
{
|
||||||
|
split(it->first, "\0"_sv)
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto &event_id
|
||||||
|
{
|
||||||
|
parts.first
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto &event_idx
|
||||||
|
{
|
||||||
|
byte_view<event::idx>(parts.second)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!closure(event_id, event_idx))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
char buf[m::dbs::EVENT_HORIZON_KEY_MAX_SIZE];
|
char buf[m::dbs::EVENT_HORIZON_KEY_MAX_SIZE];
|
||||||
const string_view &key
|
const string_view &key
|
||||||
{
|
{
|
||||||
m::dbs::event_horizon_key(buf, event_id, 0UL)
|
m::dbs::event_horizon_key(buf, event_id, 0UL)
|
||||||
};
|
};
|
||||||
|
|
||||||
auto it
|
for(auto it(m::dbs::event_horizon.begin(key)); it; ++it)
|
||||||
{
|
|
||||||
m::dbs::event_horizon.begin(key)
|
|
||||||
};
|
|
||||||
|
|
||||||
for(; it; ++it)
|
|
||||||
{
|
{
|
||||||
const auto &event_idx
|
const auto &event_idx
|
||||||
{
|
{
|
||||||
std::get<0>(m::dbs::event_horizon_key(it->first))
|
std::get<0>(m::dbs::event_horizon_key(it->first))
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!closure(event_idx))
|
if(!closure(event_id, event_idx))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6460,7 +6460,7 @@ console_cmd__event__horizon(opt &out, const string_view &line)
|
||||||
};
|
};
|
||||||
|
|
||||||
horizon.for_each([&out, &event_id]
|
horizon.for_each([&out, &event_id]
|
||||||
(const auto &event_idx)
|
(const auto &, const auto &event_idx)
|
||||||
{
|
{
|
||||||
const auto _event_id
|
const auto _event_id
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue