0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd:Ⓜ️:room::state: Reconnect !present() branch with state::history.

This commit is contained in:
Jason Volk 2019-06-16 02:18:04 -07:00
parent 24ce076c3d
commit 4f741960a0
2 changed files with 82 additions and 13 deletions

View file

@ -34,6 +34,7 @@ struct ircd::m::room::state
using closure_bool = std::function<bool (const string_view &, const string_view &, const event::idx &)>; using closure_bool = std::function<bool (const string_view &, const string_view &, const event::idx &)>;
IRCD_STRONG_TYPEDEF(string_view, type_prefix) IRCD_STRONG_TYPEDEF(string_view, type_prefix)
static conf::item<bool> enable_history;
static conf::item<size_t> readahead_size; static conf::item<size_t> readahead_size;
room::id room_id; room::id room_id;

View file

@ -1858,6 +1858,13 @@ ircd::m::room::messages::fetch(std::nothrow_t)
// room::state // 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) decltype(ircd::m::room::state::readahead_size)
ircd::m::room::state::readahead_size ircd::m::room::state::readahead_size
{ {
@ -1977,7 +1984,12 @@ const try
{ {
if(!present()) if(!present())
{ {
assert(0); const history history
{
room_id, event_id
};
closure(history.get(type, state_key));
return; return;
} }
@ -2043,8 +2055,22 @@ const
{ {
if(!present()) if(!present())
{ {
assert(0); const history history
return false; {
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}; auto &column{dbs::room_state};
@ -2073,8 +2099,12 @@ const
{ {
if(!present()) if(!present())
{ {
assert(0); const history history
return false; {
room_id, event_id
};
return history.has(type, state_key);
} }
auto &column{dbs::room_state}; auto &column{dbs::room_state};
@ -2194,8 +2224,16 @@ const
{ {
if(!present()) if(!present())
{ {
assert(0); const history history
return true; {
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 db::gopts opts
@ -2360,8 +2398,16 @@ const
{ {
if(!present()) if(!present())
{ {
assert(0); const history history
return true; {
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]; char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
@ -2426,8 +2472,16 @@ const
{ {
if(!present()) if(!present())
{ {
assert(0); const history history
return true; {
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]; char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
@ -2503,8 +2557,16 @@ const
if(!present()) if(!present())
{ {
assert(0); const history history
return true; {
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]; char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
@ -2557,6 +2619,12 @@ const
if(!event_id) if(!event_id)
return true; 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 // Check the cached value from a previous false result of this function
// before doing any real work/IO below. If this function ever returned // before doing any real work/IO below. If this function ever returned
// false it will never return true after. // false it will never return true after.