From 4f741960a0272a160970db0ec4e86c0a3997f20e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 16 Jun 2019 02:18:04 -0700 Subject: [PATCH] ircd::m::room::state: Reconnect !present() branch with state::history. --- include/ircd/m/room/state.h | 1 + ircd/m_room.cc | 94 ++++++++++++++++++++++++++++++++----- 2 files changed, 82 insertions(+), 13 deletions(-) diff --git a/include/ircd/m/room/state.h b/include/ircd/m/room/state.h index 3b9edfcd5..3b27c5e5d 100644 --- a/include/ircd/m/room/state.h +++ b/include/ircd/m/room/state.h @@ -34,6 +34,7 @@ struct ircd::m::room::state using closure_bool = std::function; IRCD_STRONG_TYPEDEF(string_view, type_prefix) + static conf::item enable_history; static conf::item readahead_size; room::id room_id; diff --git a/ircd/m_room.cc b/ircd/m_room.cc index 325a8d879..4595d9a8b 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -1858,6 +1858,13 @@ ircd::m::room::messages::fetch(std::nothrow_t) // room::state // +decltype(ircd::m::room::state::enable_history) +ircd::m::room::state::enable_history +{ + { "name", "ircd.m.room.state.enable_history" }, + { "default", true }, +}; + decltype(ircd::m::room::state::readahead_size) ircd::m::room::state::readahead_size { @@ -1977,7 +1984,12 @@ const try { if(!present()) { - assert(0); + const history history + { + room_id, event_id + }; + + closure(history.get(type, state_key)); return; } @@ -2043,8 +2055,22 @@ const { if(!present()) { - assert(0); - return false; + const history history + { + room_id, event_id + }; + + const auto event_idx + { + history.get(std::nothrow, type, state_key) + }; + + if(event_idx) + { + closure(event_idx); + return true; + } + else return false; } auto &column{dbs::room_state}; @@ -2073,8 +2099,12 @@ const { if(!present()) { - assert(0); - return false; + const history history + { + room_id, event_id + }; + + return history.has(type, state_key); } auto &column{dbs::room_state}; @@ -2194,8 +2224,16 @@ const { if(!present()) { - assert(0); - return true; + const history history + { + room_id, event_id + }; + + return history.for_each([&closure] + (const auto &type, const auto &state_key, const auto &depth, const auto &event_idx) + { + return closure(type, state_key, event_idx); + }); } db::gopts opts @@ -2360,8 +2398,16 @@ const { if(!present()) { - assert(0); - return true; + const history history + { + room_id, event_id + }; + + return history.for_each(type, state_key_lb, [&closure] + (const auto &type, const auto &state_key, const auto &depth, const auto &event_idx) + { + return closure(type, state_key, event_idx); + }); } char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE]; @@ -2426,8 +2472,16 @@ const { if(!present()) { - assert(0); - return true; + const history history + { + room_id, event_id + }; + + return history.for_each(type, state_key_lb, [&closure] + (const auto &, const auto &state_key, const auto &, const auto &) + { + return closure(state_key); + }); } char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE]; @@ -2503,8 +2557,16 @@ const if(!present()) { - assert(0); - return true; + const history history + { + room_id, event_id + }; + + return history.for_each([&closure] + (const auto &type, const auto &, const auto &, const auto &) + { + return closure(type); + }); } char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE]; @@ -2557,6 +2619,12 @@ const if(!event_id) return true; + // When the global configuration disables history, always consider the + // present state. (disabling may yield unexpected incorrect results by + // returning the present state without error). + if(!enable_history) + return true; + // Check the cached value from a previous false result of this function // before doing any real work/IO below. If this function ever returned // false it will never return true after.