0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 15:04:10 +01:00

ircd:Ⓜ️:room::members: Eliminate unnecessary query to the room state.

This commit is contained in:
Jason Volk 2020-06-14 20:03:51 -07:00
parent 942e8330e6
commit 4ef7754ed5
3 changed files with 31 additions and 18 deletions

View file

@ -23,7 +23,7 @@ struct ircd::m::room::members
m::room room;
bool for_each_join_present(const string_view &host, const closure &) const;
bool for_each_join_present(const string_view &host, const closure_idx &) const;
public:
bool for_each(const string_view &membership, const string_view &host, const closure &) const;

View file

@ -181,12 +181,19 @@ ircd::m::dbs::_index_room_joined(db::txn &txn,
else
return;
const string_view val
{
byte_view<string_view>{opts.event_idx}
};
assert(val.size() >= sizeof(event::idx));
db::txn::append
{
txn, room_joined,
{
op,
key,
val,
}
};
}

View file

@ -110,16 +110,20 @@ const
state.present()
};
const closure_idx _closure
{
[&closure](const auto &user_id, const auto &event_idx)
{
return closure(user_id);
}
};
// joined members optimization. Only possible when seeking
// membership="join" on the present state of the room.
if(membership == "join" && present)
return for_each_join_present(host, closure);
return for_each_join_present(host, _closure);
return this->for_each(membership, host, [&closure]
(const auto &user_id, const auto &event_idx)
{
return closure(user_id);
});
return this->for_each(membership, host, _closure);
}
bool
@ -142,12 +146,10 @@ const
// membership="join" on the present state of the room.
if(membership == "join" && present)
return for_each_join_present(host, [&closure, &state]
(const id::user &user_id)
(const id::user &user_id, event::idx event_idx)
{
const auto &event_idx
{
state.get(std::nothrow, "m.room.member", user_id)
};
if(!event_idx)
event_idx = state.get(std::nothrow, "m.room.member", user_id);
if(unlikely(!event_idx))
{
@ -162,10 +164,7 @@ const
return true;
}
if(!closure(user_id, event_idx))
return false;
return true;
return closure(user_id, event_idx);
});
return state.for_each("m.room.member", [this, &host, &membership, &closure]
@ -187,7 +186,7 @@ const
bool
ircd::m::room::members::for_each_join_present(const string_view &host,
const closure &closure)
const closure_idx &closure)
const
{
db::domain &index
@ -216,7 +215,14 @@ const
if(host && origin != host)
break;
if(!closure(user_id))
const event::idx event_idx
{
it->second.size() >= sizeof(event::idx)?
event::idx(byte_view<event::idx>(it->second)):
0UL
};
if(!closure(user_id, event_idx))
return false;
}