0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 18:18:56 +02:00

ircd:Ⓜ️:vm::eval: Add count(event_id) to static interface.

This commit is contained in:
Jason Volk 2019-09-11 12:51:54 -07:00
parent 83c58cf42e
commit fac2a1e070
2 changed files with 25 additions and 0 deletions

View file

@ -105,6 +105,7 @@ struct ircd::m::vm::eval
static bool for_each(const ctx::ctx *const &, const std::function<bool (eval &)> &);
static bool for_each(const std::function<bool (eval &)> &);
static size_t count(const ctx::ctx *const &);
static size_t count(const event::id &);
static eval *find(const event::id &);
static eval &get(const event::id &);
static bool sequnique(const uint64_t &seq);

View file

@ -1299,6 +1299,30 @@ ircd::m::vm::eval::find(const event::id &event_id)
return ret;
}
size_t
ircd::m::vm::eval::count(const event::id &event_id)
{
size_t ret(0);
for_each([&event_id, &ret](eval &e)
{
if(e.event_)
{
if(e.event_->event_id == event_id)
++ret;
}
else if(e.issue)
{
if(e.issue->has("event_id"))
if(string_view{e.issue->at("event_id")} == event_id)
++ret;
}
else if(e.event_id == event_id)
++ret;
});
return ret;
}
size_t
ircd::m::vm::eval::count(const ctx::ctx *const &c)
{