From 83cce03f6f5b016535ff8973c82dab8d225c35c3 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 18 Sep 2019 13:30:15 -0700 Subject: [PATCH] ircd::m::room::state: Add prefetch() support to state::history/state::space. --- include/ircd/m/room/state_history.h | 3 ++ include/ircd/m/room/state_space.h | 4 +++ ircd/m_room.cc | 50 +++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/include/ircd/m/room/state_history.h b/include/ircd/m/room/state_history.h index 40b0cae7a..c054992e7 100644 --- a/include/ircd/m/room/state_history.h +++ b/include/ircd/m/room/state_history.h @@ -36,6 +36,9 @@ struct ircd::m::room::state::history event::idx get(std::nothrow_t, const string_view &type, const string_view &state_key) const; event::idx get(const string_view &type, const string_view &state_key) const; + bool prefetch(const string_view &type, const string_view &state_key) const; + bool prefetch(const string_view &type) const; + history(const m::room &, const int64_t &bound); history(const m::room::id &, const m::event::id &); history(const m::room &); diff --git a/include/ircd/m/room/state_space.h b/include/ircd/m/room/state_space.h index 3810d13df..21fdf6f7e 100644 --- a/include/ircd/m/room/state_space.h +++ b/include/ircd/m/room/state_space.h @@ -39,6 +39,10 @@ struct ircd::m::room::state::space bool has(const string_view &type, const string_view &state_key) const; bool has(const string_view &type) const; + bool prefetch(const string_view &type, const string_view &state_key, const int64_t &depth) const; + bool prefetch(const string_view &type, const string_view &state_key) const; + bool prefetch(const string_view &type) const; + space(const m::room &); }; diff --git a/ircd/m_room.cc b/ircd/m_room.cc index 619dc9a76..55887cad4 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -2580,6 +2580,21 @@ ircd::m::room::state::history::history(const m::room &room, { } +bool +ircd::m::room::state::history::prefetch(const string_view &type) +const +{ + return prefetch(type, string_view{}); +} + +bool +ircd::m::room::state::history::prefetch(const string_view &type, + const string_view &state_key) +const +{ + return space.prefetch(type, state_key, bound); +} + ircd::m::event::idx ircd::m::room::state::history::get(const string_view &type, const string_view &state_key) @@ -2725,6 +2740,41 @@ ircd::m::room::state::space::space(const m::room &room) { } +bool +ircd::m::room::state::space::prefetch(const string_view &type) +const +{ + return prefetch(type, string_view{}); +} + +bool +ircd::m::room::state::space::prefetch(const string_view &type, + const string_view &state_key) +const +{ + return prefetch(type, state_key, -1); +} + +bool +ircd::m::room::state::space::prefetch(const string_view &type, + const string_view &state_key, + const int64_t &depth) +const +{ + const int64_t &_depth + { + type? depth : 0L + }; + + 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, 0UL) + }; + + return db::prefetch(dbs::room_state_space, key); +} + bool ircd::m::room::state::space::has(const string_view &type) const