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

ircd:Ⓜ️:dbs: Use null separators for prefixing.

This commit is contained in:
Jason Volk 2018-03-04 00:25:27 -08:00
parent 240e01a9b5
commit 2e3d88057c
2 changed files with 40 additions and 47 deletions

View file

@ -461,8 +461,6 @@ ircd::m::dbs::desc::events__state_node
/// and the suffix is the depth+event_id concatenation. /// and the suffix is the depth+event_id concatenation.
/// for efficient sequences /// for efficient sequences
/// ///
/// TODO: This needs The Grammar
///
const ircd::db::prefix_transform const ircd::db::prefix_transform
ircd::m::dbs::desc::events__room_events__pfx ircd::m::dbs::desc::events__room_events__pfx
{ {
@ -470,12 +468,12 @@ ircd::m::dbs::desc::events__room_events__pfx
[](const string_view &key) [](const string_view &key)
{ {
return key.find(":::") != key.npos; return key.find("\0"_sv) != key.npos;
}, },
[](const string_view &key) [](const string_view &key)
{ {
return rsplit(key, ":::").first; return rsplit(key, "\0"_sv).first;
} }
}; };
@ -483,8 +481,6 @@ ircd::m::dbs::desc::events__room_events__pfx
/// events within a room by their depth from highest to lowest, so the /// events within a room by their depth from highest to lowest, so the
/// highest depth is hit first when a room is sought from this column. /// highest depth is hit first when a room is sought from this column.
/// ///
/// TODO: This needs The Grammar
///
const ircd::db::comparator const ircd::db::comparator
ircd::m::dbs::desc::events__room_events__cmp ircd::m::dbs::desc::events__room_events__cmp
{ {
@ -524,8 +520,8 @@ ircd::m::dbs::desc::events__room_events__cmp
// Now want just the depth... // Now want just the depth...
const string_view depths[2] const string_view depths[2]
{ {
between(post[0], ":::", "$"), between(post[0], "\0"_sv, "$"_sv),
between(post[1], ":::", "$"), between(post[1], "\0"_sv, "$"_sv),
}; };
// ...as machine words // ...as machine words
@ -546,48 +542,49 @@ ircd::m::dbs::desc::events__room_events__cmp
} }
}; };
//TODO: optimize
//TODO: Needs The Gramslam
ircd::string_view ircd::string_view
ircd::m::dbs::room_events_key(const mutable_buffer &out, ircd::m::dbs::room_events_key(const mutable_buffer &out_,
const id::room &room_id, const id::room &room_id,
const uint64_t &depth) const uint64_t &depth)
{ {
size_t len{0}; mutable_buffer out{out_};
len = strlcpy(out, room_id); consume(out, copy(out, room_id));
len = strlcat(out, ":::"); consume(out, copy(out, "\0"_sv));
len = strlcat(out, lex_cast(depth)); consume(out, copy(out, lex_cast(depth)));
return { data(out), len }; return { data(out_), data(out) };
} }
//TODO: optimize
//TODO: Needs The Gramslam
ircd::string_view ircd::string_view
ircd::m::dbs::room_events_key(const mutable_buffer &out, ircd::m::dbs::room_events_key(const mutable_buffer &out_,
const id::room &room_id, const id::room &room_id,
const uint64_t &depth, const uint64_t &depth,
const id::event &event_id) const id::event &event_id)
{ {
size_t len{0}; mutable_buffer out{out_};
len = strlcpy(out, room_id); consume(out, copy(out, room_id));
len = strlcat(out, ":::"); consume(out, copy(out, "\0"_sv));
len = strlcat(out, lex_cast(depth)); consume(out, copy(out, lex_cast(depth)));
len = strlcat(out, event_id); consume(out, copy(out, event_id));
return { data(out), len }; return { data(out_), data(out) };
} }
std::tuple<uint64_t, ircd::string_view> std::tuple<uint64_t, ircd::string_view>
ircd::m::dbs::room_events_key(const string_view &amalgam) ircd::m::dbs::room_events_key(const string_view &amalgam)
{ {
const auto depth const auto &key
{ {
between(amalgam, ":::", "$") lstrip(amalgam, "\0"_sv)
};
const auto &s
{
split(key, "$"_sv)
}; };
return return
{ {
lex_cast<uint64_t>(depth), lex_cast<uint64_t>(s.first),
string_view{end(depth), end(amalgam)} { end(s.first), end(s.second) }
}; };
} }
@ -654,8 +651,6 @@ ircd::m::dbs::desc::events__room_events
/// Prefix transform for the events__room_origins /// Prefix transform for the events__room_origins
/// ///
/// TODO: This needs The Grammar
///
const ircd::db::prefix_transform const ircd::db::prefix_transform
ircd::m::dbs::desc::events__room_origins__pfx ircd::m::dbs::desc::events__room_origins__pfx
{ {
@ -663,29 +658,27 @@ ircd::m::dbs::desc::events__room_origins__pfx
[](const string_view &key) [](const string_view &key)
{ {
return key.find(":::") != key.npos; return key.find("\0"_sv) != key.npos;
}, },
[](const string_view &key) [](const string_view &key)
{ {
return rsplit(key, ":::").first; return rsplit(key, "\0"_sv).first;
} }
}; };
//TODO: optimize
//TODO: Needs The Gramslam
ircd::string_view ircd::string_view
ircd::m::dbs::room_origins_key(const mutable_buffer &out, ircd::m::dbs::room_origins_key(const mutable_buffer &out_,
const id::room &room_id, const id::room &room_id,
const string_view &origin, const string_view &origin,
const id::user &member) const id::user &member)
{ {
size_t len{0}; mutable_buffer out{out_};
len = strlcpy(out, room_id); consume(out, copy(out, room_id));
len = strlcat(out, ":::"); consume(out, copy(out, "\0"_sv));
len = strlcat(out, origin); consume(out, copy(out, origin));
len = strlcat(out, member); consume(out, copy(out, member));
return { data(out), len }; return { data(out_), data(out) };
} }
std::tuple<ircd::string_view, ircd::string_view> std::tuple<ircd::string_view, ircd::string_view>
@ -693,18 +686,18 @@ ircd::m::dbs::room_origins_key(const string_view &amalgam)
{ {
const auto &key const auto &key
{ {
lstrip(amalgam, ":::") lstrip(amalgam, "\0"_sv)
}; };
const auto &s const auto &s
{ {
split(key, "@") split(key, "@"_sv)
}; };
return return
{ {
{ s.first }, { s.first },
{ end(s.first), end(key) } { end(s.first), end(s.second) }
}; };
} }

View file

@ -896,9 +896,9 @@ const
for(; bool(it); ++it) for(; bool(it); ++it)
{ {
const string_view &key //TODO: XXX const string_view &key
{ {
lstrip(it->first, ":::") lstrip(it->first, "\0"_sv)
}; };
if(view(key)) if(view(key))