0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-29 00:44:17 +01:00

ircd:Ⓜ️:dbs: Use buffer size constants for query key generations.

This commit is contained in:
Jason Volk 2018-04-24 19:19:40 -07:00
parent 12592cd22c
commit ba61369027
3 changed files with 19 additions and 16 deletions

View file

@ -33,14 +33,17 @@ namespace ircd::m::dbs
extern db::column state_node; extern db::column state_node;
// Lowlevel util // Lowlevel util
static const size_t ROOM_STATE_KEY_MAX_SIZE {id::MAX_SIZE + 256 + 256};
string_view room_state_key(const mutable_buffer &out, const id::room &, const string_view &type, const string_view &state_key); string_view room_state_key(const mutable_buffer &out, const id::room &, const string_view &type, const string_view &state_key);
string_view room_state_key(const mutable_buffer &out, const id::room &, const string_view &type); string_view room_state_key(const mutable_buffer &out, const id::room &, const string_view &type);
std::pair<string_view, string_view> room_state_key(const string_view &amalgam); std::pair<string_view, string_view> room_state_key(const string_view &amalgam);
static const size_t ROOM_JOINED_KEY_MAX_SIZE {id::MAX_SIZE + 256 + id::MAX_SIZE};
string_view room_joined_key(const mutable_buffer &out, const id::room &, const string_view &origin, const id::user &member); string_view room_joined_key(const mutable_buffer &out, const id::room &, const string_view &origin, const id::user &member);
string_view room_joined_key(const mutable_buffer &out, const id::room &, const string_view &origin); string_view room_joined_key(const mutable_buffer &out, const id::room &, const string_view &origin);
std::pair<string_view, string_view> room_joined_key(const string_view &amalgam); std::pair<string_view, string_view> room_joined_key(const string_view &amalgam);
static const size_t ROOM_EVENTS_KEY_MAX_SIZE {id::MAX_SIZE + 1 + 8 + 8};
string_view room_events_key(const mutable_buffer &out, const id::room &, const uint64_t &depth, const event::idx &); string_view room_events_key(const mutable_buffer &out, const id::room &, const uint64_t &depth, const event::idx &);
string_view room_events_key(const mutable_buffer &out, const id::room &, const uint64_t &depth); string_view room_events_key(const mutable_buffer &out, const id::room &, const uint64_t &depth);
std::pair<uint64_t, event::idx> room_events_key(const string_view &amalgam); std::pair<uint64_t, event::idx> room_events_key(const string_view &amalgam);

View file

@ -243,7 +243,7 @@ ircd::m::dbs::_index__room_events(db::txn &txn,
const string_view &new_root) const string_view &new_root)
{ {
const ctx::critical_assertion ca; const ctx::critical_assertion ca;
thread_local char buf[256 + 1 + 8 + 8]; thread_local char buf[ROOM_EVENTS_KEY_MAX_SIZE];
const string_view &key const string_view &key
{ {
room_events_key(buf, at<"room_id"_>(event), at<"depth"_>(event), opts.idx) room_events_key(buf, at<"room_id"_>(event), at<"depth"_>(event), opts.idx)
@ -274,7 +274,7 @@ ircd::m::dbs::_index__room_joined(db::txn &txn,
return; return;
const ctx::critical_assertion ca; const ctx::critical_assertion ca;
thread_local char buf[512]; thread_local char buf[ROOM_JOINED_KEY_MAX_SIZE];
const string_view &key const string_view &key
{ {
room_joined_key(buf, at<"room_id"_>(event), at<"origin"_>(event), at<"state_key"_>(event)) room_joined_key(buf, at<"room_id"_>(event), at<"origin"_>(event), at<"state_key"_>(event))
@ -328,7 +328,7 @@ ircd::m::dbs::_index__room_state(db::txn &txn,
return; return;
const ctx::critical_assertion ca; const ctx::critical_assertion ca;
thread_local char buf[768]; thread_local char buf[ROOM_STATE_KEY_MAX_SIZE];
const string_view &key const string_view &key
{ {
room_state_key(buf, at<"room_id"_>(event), at<"type"_>(event), at<"state_key"_>(event)) room_state_key(buf, at<"room_id"_>(event), at<"type"_>(event), at<"state_key"_>(event))
@ -443,7 +443,7 @@ ircd::m::dbs::state_root(const mutable_buffer &out,
const event::idx &event_idx, const event::idx &event_idx,
const uint64_t &depth) const uint64_t &depth)
{ {
char keybuf[256 + 1 + 8 + 8]; const auto key char keybuf[ROOM_EVENTS_KEY_MAX_SIZE]; const auto key
{ {
room_events_key(keybuf, room_id, depth, event_idx) room_events_key(keybuf, room_id, depth, event_idx)
}; };

View file

@ -474,7 +474,7 @@ ircd::m::room::messages::seek(const event::id &event_id)
depth = byte_view<uint64_t>(value); depth = byte_view<uint64_t>(value);
}); });
char buf[m::state::KEY_MAX_SZ]; char buf[dbs::ROOM_EVENTS_KEY_MAX_SIZE];
const auto seek_key const auto seek_key
{ {
dbs::room_events_key(buf, room.room_id, depth, event_idx) dbs::room_events_key(buf, room.room_id, depth, event_idx)
@ -487,7 +487,7 @@ ircd::m::room::messages::seek(const event::id &event_id)
bool bool
ircd::m::room::messages::seek(const uint64_t &depth) ircd::m::room::messages::seek(const uint64_t &depth)
{ {
char buf[m::state::KEY_MAX_SZ]; char buf[dbs::ROOM_EVENTS_KEY_MAX_SIZE];
const auto seek_key const auto seek_key
{ {
dbs::room_events_key(buf, room.room_id, depth) dbs::room_events_key(buf, room.room_id, depth)
@ -664,8 +664,8 @@ const try
closure(event::fetch::index(unquote(event_id))); closure(event::fetch::index(unquote(event_id)));
}); });
char key[768];
auto &column{dbs::room_state}; auto &column{dbs::room_state};
char key[dbs::ROOM_STATE_KEY_MAX_SIZE];
column(dbs::room_state_key(key, room_id, type, state_key), [&closure] column(dbs::room_state_key(key, room_id, type, state_key), [&closure]
(const string_view &value) (const string_view &value)
{ {
@ -738,8 +738,8 @@ const
return closure(event::fetch::index(unquote(event_id), std::nothrow)); return closure(event::fetch::index(unquote(event_id), std::nothrow));
}); });
char key[768];
auto &column{dbs::room_state}; auto &column{dbs::room_state};
char key[dbs::ROOM_STATE_KEY_MAX_SIZE];
return column(dbs::room_state_key(key, room_id, type, state_key), std::nothrow, [&closure] return column(dbs::room_state_key(key, room_id, type, state_key), std::nothrow, [&closure]
(const string_view &value) (const string_view &value)
{ {
@ -767,8 +767,8 @@ const
(const string_view &event_id) (const string_view &event_id)
{}); {});
char key[768];
auto &column{dbs::room_state}; auto &column{dbs::room_state};
char key[dbs::ROOM_STATE_KEY_MAX_SIZE];
return db::has(column, dbs::room_state_key(key, room_id, type, state_key)); return db::has(column, dbs::room_state_key(key, room_id, type, state_key));
} }
@ -794,7 +794,7 @@ const
if(root_id) if(root_id)
return m::state::count(root_id, type); return m::state::count(root_id, type);
char keybuf[768]; char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
const auto &key const auto &key
{ {
dbs::room_state_key(keybuf, room_id, type) dbs::room_state_key(keybuf, room_id, type)
@ -926,7 +926,7 @@ const
return closure(event::fetch::index(unquote(event_id), std::nothrow)); return closure(event::fetch::index(unquote(event_id), std::nothrow));
}); });
char keybuf[768]; char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
const auto &key const auto &key
{ {
dbs::room_state_key(keybuf, room_id, type) dbs::room_state_key(keybuf, room_id, type)
@ -957,7 +957,7 @@ const
return closure(unquote(key.at(1))); return closure(unquote(key.at(1)));
}); });
char keybuf[768]; char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
const auto &key const auto &key
{ {
dbs::room_state_key(keybuf, room_id, type) dbs::room_state_key(keybuf, room_id, type)
@ -1040,7 +1040,7 @@ const
return closure(event::fetch::index(unquote(event_id), std::nothrow)); return closure(event::fetch::index(unquote(event_id), std::nothrow));
}); });
char keybuf[768]; char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
const auto &key const auto &key
{ {
dbs::room_state_key(keybuf, room_id, type, state_key_lb) dbs::room_state_key(keybuf, room_id, type, state_key_lb)
@ -1150,7 +1150,7 @@ const
closure(event::fetch::index(unquote(event_id), std::nothrow)); closure(event::fetch::index(unquote(event_id), std::nothrow));
}); });
char keybuf[768]; char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
const auto &key const auto &key
{ {
dbs::room_state_key(keybuf, room_id, type) dbs::room_state_key(keybuf, room_id, type)
@ -1177,7 +1177,7 @@ const
closure(unquote(key.at(1))); closure(unquote(key.at(1)));
}); });
char keybuf[768]; char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
const auto &key const auto &key
{ {
dbs::room_state_key(keybuf, room_id, type) dbs::room_state_key(keybuf, room_id, type)
@ -1393,7 +1393,7 @@ const
dbs::room_joined dbs::room_joined
}; };
char querybuf[512]; char querybuf[dbs::ROOM_JOINED_KEY_MAX_SIZE];
const auto query const auto query
{ {
dbs::room_joined_key(querybuf, room.room_id, origin) dbs::room_joined_key(querybuf, room.room_id, origin)