mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 07:23:53 +01:00
modules/m_room_aliases: Consolidate state_key creation; case desensitize.
This commit is contained in:
parent
48da12c306
commit
3dfb593dec
2 changed files with 33 additions and 6 deletions
|
@ -44,6 +44,7 @@ struct ircd::m::room::aliases::cache
|
|||
struct entity;
|
||||
using closure_bool = std::function<bool (const alias &, const id &)>;
|
||||
|
||||
static string_view make_key(const mutable_buffer &, const alias &);
|
||||
static event::idx getidx(const alias &); // nothrow
|
||||
static milliseconds age(const event::idx &); // nothrow
|
||||
static bool expired(const event::idx &); // nothrow
|
||||
|
|
|
@ -227,10 +227,10 @@ bool
|
|||
IRCD_MODULE_EXPORT
|
||||
ircd::m::room::aliases::cache::del(const alias &alias)
|
||||
{
|
||||
char swapbuf[m::id::room_alias::buf::SIZE];
|
||||
char buf[m::id::room_alias::buf::SIZE];
|
||||
const string_view &key
|
||||
{
|
||||
alias.swap(swapbuf)
|
||||
make_key(buf, alias)
|
||||
};
|
||||
|
||||
const auto &event_idx
|
||||
|
@ -262,10 +262,10 @@ IRCD_MODULE_EXPORT
|
|||
ircd::m::room::aliases::cache::set(const alias &alias,
|
||||
const id &id)
|
||||
{
|
||||
char swapbuf[m::id::room_alias::buf::SIZE];
|
||||
char buf[m::id::room_alias::buf::SIZE];
|
||||
const string_view &key
|
||||
{
|
||||
alias.swap(swapbuf)
|
||||
make_key(buf, alias)
|
||||
};
|
||||
|
||||
const auto ret
|
||||
|
@ -554,12 +554,18 @@ ircd::m::event::idx
|
|||
IRCD_MODULE_EXPORT
|
||||
ircd::m::room::aliases::cache::getidx(const alias &alias)
|
||||
{
|
||||
char swapbuf[m::id::room_alias::buf::SIZE];
|
||||
const string_view &key
|
||||
thread_local char swapbuf[m::id::room_alias::buf::SIZE];
|
||||
const string_view &swapped
|
||||
{
|
||||
alias.swap(swapbuf)
|
||||
};
|
||||
|
||||
char buf[m::id::room_alias::buf::SIZE];
|
||||
const string_view &key
|
||||
{
|
||||
tolower(buf, swapped)
|
||||
};
|
||||
|
||||
const auto &event_idx
|
||||
{
|
||||
alias_room.get(std::nothrow, "ircd.room.alias", key)
|
||||
|
@ -567,3 +573,23 @@ ircd::m::room::aliases::cache::getidx(const alias &alias)
|
|||
|
||||
return event_idx;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::room::aliases::cache::make_key(const mutable_buffer &out,
|
||||
const alias &alias)
|
||||
{
|
||||
|
||||
thread_local char swapbuf[m::id::room_alias::buf::SIZE] alignas(16);
|
||||
const string_view &swapped
|
||||
{
|
||||
alias.swap(swapbuf)
|
||||
};
|
||||
|
||||
const string_view &key
|
||||
{
|
||||
tolower(out, swapped)
|
||||
};
|
||||
|
||||
return key;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue