0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-04 21:08:57 +01:00

ircd:Ⓜ️:dbs: Typedef a tuple for room_space key; conditions for truncated key generation.

This commit is contained in:
Jason Volk 2019-05-13 10:19:18 -07:00
parent e486d8907e
commit d1425da434
2 changed files with 23 additions and 3 deletions

View file

@ -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;

View file

@ -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