mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 01:30:12 +01:00
ircd:Ⓜ️:room: Add lower_bound state_key only iteration to interface.
This commit is contained in:
parent
537b7e26aa
commit
ba70c1b128
2 changed files with 44 additions and 0 deletions
|
@ -262,6 +262,7 @@ struct ircd::m::room::state
|
|||
void for_each(const types &) const;
|
||||
bool for_each(const string_view &type, const keys_bool &view) const;
|
||||
void for_each(const string_view &type, const keys &) const;
|
||||
bool for_each(const string_view &type, const string_view &lower_bound, const keys_bool &view) const;
|
||||
bool for_each(const string_view &type, const string_view &lower_bound, const event::closure_idx_bool &view) const;
|
||||
bool for_each(const string_view &type, const string_view &lower_bound, const event::id::closure_bool &view) const;
|
||||
bool for_each(const string_view &type, const string_view &lower_bound, const event::closure_bool &view) const;
|
||||
|
|
|
@ -1297,6 +1297,49 @@ const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::room::state::for_each(const string_view &type,
|
||||
const string_view &state_key_lb,
|
||||
const keys_bool &closure)
|
||||
const
|
||||
{
|
||||
if(!present())
|
||||
return !m::state::test(root_id, type, state_key_lb, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
char buf[dbs::ROOM_STATE_KEY_MAX_SIZE];
|
||||
return !closure(m::state::unmake_key(buf, key));
|
||||
});
|
||||
|
||||
char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
|
||||
const auto &key
|
||||
{
|
||||
dbs::room_state_key(keybuf, room_id, type, state_key_lb)
|
||||
};
|
||||
|
||||
db::gopts opts
|
||||
{
|
||||
this->fopts? this->fopts->gopts : db::gopts{}
|
||||
};
|
||||
|
||||
if(!opts.readahead)
|
||||
opts.readahead = 0_KiB;
|
||||
|
||||
auto &column{dbs::room_state};
|
||||
for(auto it{column.begin(key, opts)}; bool(it); ++it)
|
||||
{
|
||||
const auto key(dbs::room_state_key(it->first));
|
||||
if(std::get<0>(key) == type)
|
||||
{
|
||||
if(!closure(std::get<1>(key)))
|
||||
return false;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::room::state::for_each(const string_view &type,
|
||||
const keys &closure)
|
||||
|
|
Loading…
Add table
Reference in a new issue