mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 15:30:52 +01:00
ircd:Ⓜ️:dbs: Typedef a tuple for room_space key; conditions for truncated key generation.
This commit is contained in:
parent
e486d8907e
commit
d1425da434
2 changed files with 23 additions and 3 deletions
|
@ -13,15 +13,21 @@
|
|||
|
||||
namespace ircd::m::dbs
|
||||
{
|
||||
using room_space_key_parts = std::tuple<string_view, string_view, int64_t, event::idx>;
|
||||
|
||||
constexpr size_t ROOM_SPACE_KEY_MAX_SIZE
|
||||
{
|
||||
id::MAX_SIZE + event::TYPE_MAX_SIZE + event::STATE_KEY_MAX_SIZE + sizeof(int64_t)
|
||||
id::MAX_SIZE +
|
||||
event::TYPE_MAX_SIZE +
|
||||
event::STATE_KEY_MAX_SIZE +
|
||||
sizeof(int64_t) +
|
||||
sizeof(event::idx)
|
||||
};
|
||||
|
||||
string_view room_space_key(const mutable_buffer &out, const id::room &, const string_view &type, const string_view &state_key, const int64_t &depth, const event::idx & = 0);
|
||||
string_view room_space_key(const mutable_buffer &out, const id::room &, const string_view &type, const string_view &state_key);
|
||||
string_view room_space_key(const mutable_buffer &out, const id::room &, const string_view &type);
|
||||
std::tuple<string_view, string_view, int64_t, event::idx> room_space_key(const string_view &amalgam);
|
||||
room_space_key_parts room_space_key(const string_view &amalgam);
|
||||
|
||||
// room_id | type, state_key, depth, event_idx => --
|
||||
extern db::index room_space;
|
||||
|
|
|
@ -3225,17 +3225,31 @@ ircd::m::dbs::room_space_key(const mutable_buffer &out_,
|
|||
consume(out, copy(out, type));
|
||||
|
||||
if(!defined(state_key))
|
||||
{
|
||||
assert(depth < 0L && !event_idx);
|
||||
return { data(out_), data(out) };
|
||||
}
|
||||
|
||||
consume(out, copy(out, "\0"_sv));
|
||||
consume(out, copy(out, state_key));
|
||||
consume(out, copy(out, "\0"_sv));
|
||||
|
||||
if(depth < 0)
|
||||
{
|
||||
assert(!event_idx);
|
||||
return { data(out_), data(out) };
|
||||
}
|
||||
|
||||
consume(out, copy(out, byte_view<string_view>(depth)));
|
||||
|
||||
if(!event_idx)
|
||||
return { data(out_), data(out) };
|
||||
|
||||
consume(out, copy(out, byte_view<string_view>(event_idx)));
|
||||
return { data(out_), data(out) };
|
||||
}
|
||||
|
||||
std::tuple<ircd::string_view, ircd::string_view, int64_t, ircd::m::event::idx>
|
||||
ircd::m::dbs::room_space_key_parts
|
||||
ircd::m::dbs::room_space_key(const string_view &amalgam)
|
||||
{
|
||||
const auto &key
|
||||
|
|
Loading…
Reference in a new issue