From 7b48bc9f40c498e6523ef0e7410a5f4f201737fb Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 4 Feb 2018 19:34:59 -0800 Subject: [PATCH] ircd::m::dbs: Checkpoint the meta-index "state_head for event_id in room_id" --- ircd/m/dbs.cc | 26 +++++++++++++++++++------- modules/db/events.cc | 6 +++--- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/ircd/m/dbs.cc b/ircd/m/dbs.cc index eb1fead60..9e076f21e 100644 --- a/ircd/m/dbs.cc +++ b/ircd/m/dbs.cc @@ -16,6 +16,7 @@ namespace ircd::m extern std::set> indexers; extern const std::unique_ptr indexer_origin_joined; + extern const std::unique_ptr indexer_state_head_for_event_id_in_room_id; } struct ircd::m::indexer @@ -29,7 +30,8 @@ struct ircd::m::indexer std::string name; - virtual void operator()(const event &, db::txn &txn, const db::op &op) const {} + virtual void operator()(const event &, db::txn &, const db::op &op) const {} + virtual void operator()(const event &, db::txn &, const db::op &op, const string_view &) const {} indexer(std::string name) :name{std::move(name)} @@ -104,9 +106,6 @@ ircd::m::dbs::write(const event &event, txn, at<"event_id"_>(event), event }; - if(defined(json::get<"state_key"_>(event))) - state::append_nodes(txn, event); - append_indexes(event, txn); } @@ -120,6 +119,14 @@ ircd::m::dbs::append_indexes(const event &event, indexer(event, txn, db::op::SET); } + if(defined(json::get<"state_key"_>(event))) + { + char headbuf[state::ID_MAX_SZ]; + const auto head{state::insert(txn, headbuf, event)}; + const m::indexer &indexer{*indexer_state_head_for_event_id_in_room_id}; + indexer(event, txn, db::op::SET, head); + } + if(json::get<"type"_>(event) == "m.room.member") { const m::indexer &indexer{*indexer_origin_joined}; @@ -526,7 +533,7 @@ struct ircd::m::indexer::concat_v std::string col_c; void operator()(const event &, db::txn &, const db::op &op) const final override; - void operator()(const event &, db::txn &, const db::op &op, const string_view &) const; + void operator()(const event &, db::txn &, const db::op &op, const string_view &) const final override; concat_v(std::string col_a, std::string col_b, std::string col_c) :indexer @@ -696,7 +703,7 @@ struct ircd::m::indexer::concat_3vs std::string col_b2; std::string col_c; - void operator()(const event &, db::txn &, const db::op &op, const string_view &prev_event_id) const; + void operator()(const event &, db::txn &, const db::op &op, const string_view &prev_event_id) const final override; concat_3vs(std::string col_a, std::string col_b0, std::string col_b1, std::string col_b2, std::string col_c) :indexer @@ -790,7 +797,6 @@ decltype(ircd::m::indexers) ircd::m::indexers {{ std::make_shared("event_id", "sender"), - std::make_shared("event_id", "room_id"), std::make_shared("origin", "room_id"), std::make_shared("event_id", "type", "state_key", "room_id"), std::make_shared("prev_event_id", "type", "state_key", "event_id", "room_id"), @@ -802,6 +808,12 @@ ircd::m::indexer_origin_joined std::make_unique("origin", "room_id", "origin_joined in room_id") }; +decltype(ircd::m::indexer_state_head_for_event_id_in_room_id) +ircd::m::indexer_state_head_for_event_id_in_room_id +{ + std::make_unique("state_head", "event_id", "room_id") +}; + // // // diff --git a/modules/db/events.cc b/modules/db/events.cc index 02ab22b4a..f8bcdd026 100644 --- a/modules/db/events.cc +++ b/modules/db/events.cc @@ -398,10 +398,10 @@ const database::descriptor event_id_in_sender event_id_in, }; -const database::descriptor event_id_in_room_id +const database::descriptor state_head_for_event_id_in_room_id { // name - "event_id in room_id", + "state_head for event_id in room_id", // explanation R"(### developer note: @@ -742,7 +742,7 @@ const database::description events_description // * broad but useful in cases // ? eliminate for prev_event? // ? eliminate/combine with state tree related? - event_id_in_room_id, + state_head_for_event_id_in_room_id, // (room_id, origin) => () // Sequence of all origins for a room, EVER