mirror of
https://github.com/matrix-construct/construct
synced 2024-12-28 16:34:13 +01:00
ircd:Ⓜ️ Add room::members::count() with membership=join optimized path.
This commit is contained in:
parent
7a860964c4
commit
c676d56dcd
2 changed files with 51 additions and 0 deletions
|
@ -226,6 +226,9 @@ struct ircd::m::room::members
|
|||
{
|
||||
m::room room;
|
||||
|
||||
size_t count() const;
|
||||
size_t count(const string_view &membership) const;
|
||||
|
||||
bool test(const string_view &membership, const event::closure_bool &view) const;
|
||||
bool test(const event::closure_bool &view) const;
|
||||
|
||||
|
|
|
@ -639,6 +639,54 @@ const
|
|||
});
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::room::members::count(const string_view &membership)
|
||||
const
|
||||
{
|
||||
// joined members optimization. Only possible when seeking
|
||||
// membership="join" on the present state of the room.
|
||||
if(!room.event_id && membership == "join")
|
||||
{
|
||||
size_t ret{0};
|
||||
const room::origins origins{room};
|
||||
origins._test_([&ret](const string_view &)
|
||||
{
|
||||
++ret;
|
||||
return false;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const room::state state
|
||||
{
|
||||
room
|
||||
};
|
||||
|
||||
size_t ret{0};
|
||||
static const string_view type{"m.room.member"};
|
||||
state.for_each(type, event::closure{[&ret, &membership]
|
||||
(const m::event &event)
|
||||
{
|
||||
ret += m::membership(event) == membership;
|
||||
}});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::room::members::count()
|
||||
const
|
||||
{
|
||||
const room::state state
|
||||
{
|
||||
room
|
||||
};
|
||||
|
||||
static const string_view type{"m.room.member"};
|
||||
return state.count(type);
|
||||
}
|
||||
|
||||
//
|
||||
// room::origins
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue