0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd:Ⓜ️:event::fetch: Add internal buffer for event::id state.

This commit is contained in:
Jason Volk 2019-07-05 22:22:18 -07:00
parent 261151f539
commit dc4d13bca6
2 changed files with 42 additions and 3 deletions

View file

@ -45,6 +45,7 @@ struct ircd::m::event::fetch
db::cell _json;
db::row row;
bool valid;
id::buf event_id_buf;
static string_view key(const event::idx *const &);
static bool should_seek_json(const opts &);
@ -61,9 +62,9 @@ struct ircd::m::event::fetch
namespace ircd::m
{
bool seek(event::fetch &, const event::idx &, const event::id &, std::nothrow_t);
bool seek(event::fetch &, const event::idx &, std::nothrow_t);
void seek(event::fetch &, const event::idx &);
bool seek(event::fetch &, const event::id &, std::nothrow_t);
void seek(event::fetch &, const event::id &);
}

View file

@ -1331,7 +1331,7 @@ ircd::m::seek(event::fetch &fetch,
return fetch.valid;
}
return seek(fetch, event_idx, std::nothrow);
return seek(fetch, event_idx, event_id, std::nothrow);
}
void
@ -1350,7 +1350,26 @@ ircd::m::seek(event::fetch &fetch,
const event::idx &event_idx,
std::nothrow_t)
{
const auto &event_id
{
m::event_id(event_idx, fetch.event_id_buf, std::nothrow)
};
return seek(fetch, event_idx, event_id, std::nothrow);
}
bool
ircd::m::seek(event::fetch &fetch,
const event::idx &event_idx,
const event::id &event_id,
std::nothrow_t)
{
if(fetch.event_id_buf != event_id)
fetch.event_id_buf = event_id;
fetch.event_id = fetch.event_id_buf;
fetch.event_idx = event_idx;
const string_view &key
{
byte_view<string_view>(event_idx)
@ -1510,14 +1529,26 @@ ircd::m::event::fetch::assign_from_json(const string_view &key)
_json.val()
};
const bool source_event_id
{
!event_id_buf && source.has("event_id")
};
assert(fopts);
event =
{
source, event::keys{fopts->keys}
source,
source_event_id?
id(unquote(source.at("event_id"))):
m::event_id(event_idx, event_id_buf, std::nothrow),
event::keys{fopts->keys}
};
assert(!empty(source));
assert(data(event.source) == data(source));
if(unlikely(!event.event_id))
return false;
return true;
}
@ -1534,6 +1565,13 @@ ircd::m::event::fetch::assign_from_row(const string_view &key)
assign(event, row, key);
event.source = {};
event.event_id = !event_id_buf && defined(json::get<"event_id"_>(*this))?
id{json::get<"event_id"_>(*this)}:
m::event_id(event_idx, event_id_buf, std::nothrow);
if(unlikely(!event.event_id))
return false;
return true;
}