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

ircd:Ⓜ️:events: Start a content scanning interface.

This commit is contained in:
Jason Volk 2020-09-06 02:35:03 -07:00
parent 99314a1c16
commit cc123836ef
2 changed files with 50 additions and 0 deletions

View file

@ -84,6 +84,14 @@ namespace ircd::m::events::state
bool for_each(const closure &);
}
/// Interface to scan the content of events
namespace ircd::m::events::content
{
using closure = std::function<bool (const event::idx &, const json::object &)>;
bool for_each(const closure &);
}
/// Range to start (inclusive) and stop (exclusive). If start is greater than
/// stop a reverse iteration will occur. -1 (or unsigned max value) can be used
/// to start or stop at the end. 0 can be used to start or stop at the beginning.

View file

@ -347,6 +347,48 @@ ircd::m::events::for_each(const range &range,
// events::state
//
bool
ircd::m::events::content::for_each(const closure &closure)
{
constexpr auto content_idx
{
json::indexof<event, "content"_>()
};
db::column &column
{
dbs::event_column.at(content_idx)
};
static const db::gopts gopts
{
db::get::NO_CACHE,
db::get::NO_CHECKSUM
};
for(auto it(column.begin(gopts)); bool(it); ++it)
{
const auto &event_idx
{
byte_view<uint64_t>(it->first)
};
const json::object &content
{
it->second
};
if(!closure(event_idx, content))
return false;
}
return true;
}
//
// events::state
//
bool
ircd::m::events::state::for_each(const closure &closure)
{