From b5a61a7a6bfebf8f4481d64a4f034298b70e5d02 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 16 Jun 2019 00:12:06 -0700 Subject: [PATCH] ircd::m::room::state::space: Improve interface; fixes. --- include/ircd/m/room/state_space.h | 7 ++++++- ircd/m_dbs.cc | 2 +- ircd/m_room.cc | 20 ++------------------ 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/include/ircd/m/room/state_space.h b/include/ircd/m/room/state_space.h index e7dde3cb7..11f59554a 100644 --- a/include/ircd/m/room/state_space.h +++ b/include/ircd/m/room/state_space.h @@ -11,7 +11,11 @@ #pragma once #define HAVE_IRCD_M_ROOM_STATE_SPACE_H -/// Interface to all room states. +/// Interface to all room states. This is a super-dimension of m::room::state. +/// This contains all state events without overwriting them; we refer to this +/// as the state-space. We use this interface as a tool to reconstruct the +/// state of the room at the point of an event in the past; or efficiently +/// rebuild the present state table after inconsistencies, etc. /// struct ircd::m::room::state::space { @@ -20,6 +24,7 @@ struct ircd::m::room::state::space m::room room; + public: bool for_each(const string_view &type, const string_view &state_key, const int64_t &depth, const closure &) const; bool for_each(const string_view &type, const string_view &state_key, const closure &) const; bool for_each(const string_view &type, const closure &) const; diff --git a/ircd/m_dbs.cc b/ircd/m_dbs.cc index 8b16f8f13..51b484fbb 100644 --- a/ircd/m_dbs.cc +++ b/ircd/m_dbs.cc @@ -3116,7 +3116,6 @@ ircd::m::dbs::room_state_space_key(const mutable_buffer &out_, consume(out, copy(out, "\0"_sv)); consume(out, copy(out, state_key)); - consume(out, copy(out, "\0"_sv)); if(depth < 0) { @@ -3124,6 +3123,7 @@ ircd::m::dbs::room_state_space_key(const mutable_buffer &out_, return { data(out_), data(out) }; } + consume(out, copy(out, "\0"_sv)); consume(out, copy(out, byte_view(depth))); if(!event_idx) diff --git a/ircd/m_room.cc b/ircd/m_room.cc index 285d7db89..189b2723d 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -2657,23 +2657,7 @@ bool ircd::m::room::state::space::for_each(const closure &closure) const { - auto it - { - dbs::room_state_space.begin(room.room_id) - }; - - for(; it; ++it) - { - const auto &key - { - dbs::room_state_space_key(it->first) - }; - - if(!closure(std::get<0>(key), std::get<1>(key), std::get<2>(key), std::get<3>(key))) - return false; - } - - return true; + return for_each(string_view{}, string_view{}, -1L, closure); } bool @@ -2703,7 +2687,7 @@ const char buf[dbs::ROOM_STATE_SPACE_KEY_MAX_SIZE]; const string_view &key { - dbs::room_state_space_key(buf, room.room_id, type, state_key, depth) + dbs::room_state_space_key(buf, room.room_id, type, state_key, depth, -1UL) }; auto it