mirror of
https://github.com/matrix-construct/construct
synced 2025-01-13 08:23:56 +01:00
ircd:Ⓜ️:events: Start a content scanning interface.
This commit is contained in:
parent
99314a1c16
commit
cc123836ef
2 changed files with 50 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue