0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-15 14:31:11 +01:00

ircd:Ⓜ️:room: Conditional reuse of keys for_each path.

This commit is contained in:
Jason Volk 2018-10-23 14:25:14 -07:00
parent 16ac997220
commit c9426a3616

View file

@ -1297,49 +1297,6 @@ const
return true; 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 void
ircd::m::room::state::for_each(const string_view &type, ircd::m::room::state::for_each(const string_view &type,
const keys &closure) const keys &closure)
@ -1357,18 +1314,37 @@ bool
ircd::m::room::state::for_each(const string_view &type, ircd::m::room::state::for_each(const string_view &type,
const keys_bool &closure) const keys_bool &closure)
const const
{
return for_each(type, string_view{}, closure);
}
bool
ircd::m::room::state::for_each(const string_view &type,
const string_view &state_key_lb,
const keys_bool &closure)
const
{ {
if(!present()) if(!present())
return !m::state::test(root_id, type, [&closure] {
const auto btree_closure{[&closure]
(const json::array &key, const string_view &event_id) (const json::array &key, const string_view &event_id)
{ {
assert(size(key) >= 2); assert(size(key) >= 2);
return !closure(unquote(key.at(1))); return !closure(unquote(key.at(1)));
}); }};
// Must be conditional branch; empty state_key is not accepted by func.
return defined(state_key_lb)?
!m::state::test(root_id, type, state_key_lb, btree_closure):
!m::state::test(root_id, type, btree_closure);
}
char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE]; char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
const auto &key const auto &key
{ {
// Must be conditional branch; empty state_key is not accepted by func.
defined(state_key_lb)?
dbs::room_state_key(keybuf, room_id, type, state_key_lb):
dbs::room_state_key(keybuf, room_id, type) dbs::room_state_key(keybuf, room_id, type)
}; };
@ -1383,14 +1359,14 @@ const
auto &column{dbs::room_state}; auto &column{dbs::room_state};
for(auto it{column.begin(key, opts)}; bool(it); ++it) for(auto it{column.begin(key, opts)}; bool(it); ++it)
{ {
const auto part const auto key
{ {
dbs::room_state_key(it->first) dbs::room_state_key(it->first)
}; };
if(std::get<0>(part) == type) if(std::get<0>(key) == type)
{ {
if(!closure(std::get<1>(part))) if(!closure(std::get<1>(key)))
return false; return false;
} }
else break; else break;