0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

ircd:Ⓜ️ Preliminary efficient membership query object.

This commit is contained in:
Jason Volk 2017-09-25 22:17:05 -07:00
parent ffca90dd7b
commit 016ff64dbb
2 changed files with 86 additions and 0 deletions

View file

@ -39,6 +39,7 @@ struct ircd::m::room
struct alias; struct alias;
struct events; struct events;
struct state; struct state;
struct members;
using id = m::id::room; using id = m::id::room;
@ -95,3 +96,20 @@ struct ircd::m::room::state
:room_id{room.room_id} :room_id{room.room_id}
{} {}
}; };
struct ircd::m::room::members
:m::events
{
id room_id;
bool _query_(const event::where &, const event_closure_bool &) const override;
bool _rquery_(const event::where &, const event_closure_bool &) const override;
members(const id &room_id)
:room_id{room_id}
{}
members(const room &room)
:room_id{room.room_id}
{}
};

View file

@ -397,6 +397,74 @@ ircd::m::room::send(json::iov &event)
return generated_event_id; return generated_event_id;
} }
bool
ircd::m::room::members::_rquery_(const event::where &where,
const event_closure_bool &closure)
const
{
event::cursor cursor
{
"event_id for type,state_key in room_id",
&where
};
//TODO: ???
static const size_t max_type_size
{
256
};
const auto key_max
{
room::id::buf::SIZE + max_type_size
};
size_t key_len;
char key[key_max]; key[0] = '\0';
key_len = strlcat(key, room_id, sizeof(key));
key_len = strlcat(key, "..m.room.member", sizeof(key)); //TODO: prefix protocol
for(auto it(cursor.rbegin(key)); bool(it); ++it)
if(closure(*it))
return true;
return false;
}
bool
ircd::m::room::members::_query_(const event::where &where,
const event_closure_bool &closure)
const
{
event::cursor cursor
{
"event_id for type,state_key in room_id",
&where
};
//TODO: ???
static const size_t max_type_size
{
256
};
const auto key_max
{
room::id::buf::SIZE + max_type_size
};
size_t key_len;
char key[key_max]; key[0] = '\0';
key_len = strlcat(key, room_id, sizeof(key));
key_len = strlcat(key, "..m.room.member", sizeof(key)); //TODO: prefix protocol
for(auto it(cursor.begin(key)); bool(it); ++it)
if(closure(*it))
return true;
return false;
}
bool bool
ircd::m::room::state::_rquery_(const event::where &where, ircd::m::room::state::_rquery_(const event::where &where,
const event_closure_bool &closure) const event_closure_bool &closure)