0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-16 08:58:20 +02:00

ircd:Ⓜ️ Support lower_bound state_key queries into room::state.

This commit is contained in:
Jason Volk 2018-02-23 19:38:56 -08:00
parent 1a743f1705
commit f2a3e2487c
4 changed files with 53 additions and 0 deletions

View file

@ -181,6 +181,8 @@ struct ircd::m::room::state
void for_each(const event::closure &) const;
// Iterate the state; test protocol
bool test(const string_view &type, const string_view &lower_bound, const event::id::closure_bool &view) const;
bool test(const string_view &type, const string_view &lower_bound, const event::closure_bool &view) const;
bool test(const string_view &type, const event::id::closure_bool &view) const;
bool test(const string_view &type, const event::closure_bool &view) const;
bool test(const event::id::closure_bool &view) const;

View file

@ -62,6 +62,7 @@ namespace ircd::m::state
bool test(const id &root, const iter_bool_closure &);
bool test(const id &root, const string_view &type, const iter_bool_closure &);
bool test(const id &root, const string_view &type, const string_view &state_key_lb, const iter_bool_closure &);
void for_each(const id &root, const iter_closure &);
void for_each(const id &root, const string_view &type, const iter_closure &);

View file

@ -483,6 +483,37 @@ const
});
}
bool
ircd::m::room::state::test(const string_view &type,
const string_view &state_key_lb,
const event::closure_bool &closure)
const
{
event::fetch event;
return test(type, state_key_lb, event::id::closure_bool{[&event, &closure]
(const event::id &event_id)
{
if(seek(event, unquote(event_id), std::nothrow))
if(closure(event))
return true;
return false;
}});
}
bool
ircd::m::room::state::test(const string_view &type,
const string_view &state_key_lb,
const event::id::closure_bool &closure)
const
{
return m::state::test(root_id, type, state_key_lb, [&closure]
(const json::array &key, const string_view &event_id)
{
return closure(unquote(event_id));
});
}
void
ircd::m::room::state::for_each(const event::closure &closure)
const

View file

@ -170,6 +170,25 @@ ircd::m::state::test(const string_view &root,
});
}
bool
ircd::m::state::test(const string_view &root,
const string_view &type,
const string_view &state_key_lb,
const iter_bool_closure &closure)
{
char buf[KEY_MAX_SZ];
const json::array key
{
make_key(buf, type, state_key_lb)
};
return dfs(root, key, [&closure]
(const json::array &key, const string_view &val, const uint &, const uint &)
{
return closure(key, val);
});
}
namespace ircd::m::state
{
bool _dfs_recurse(const search_closure &, const node &, const json::array &key, int &);