From 04559a28f61219fd0a07aca32d38e1e451950364 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 19 Aug 2022 16:17:48 -0700 Subject: [PATCH] ircd::m::user::rooms: Add prefetch loop. --- include/ircd/m/user/rooms.h | 2 ++ matrix/user_rooms.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/ircd/m/user/rooms.h b/include/ircd/m/user/rooms.h index 5c5eb2d43..7c24fd290 100644 --- a/include/ircd/m/user/rooms.h +++ b/include/ircd/m/user/rooms.h @@ -33,6 +33,8 @@ struct ircd::m::user::rooms size_t count(const string_view &membership) const; size_t count() const; + bool prefetch() const; + rooms(const m::user &user) :user{user} {} diff --git a/matrix/user_rooms.cc b/matrix/user_rooms.cc index 0cf666ad0..da78db3af 100644 --- a/matrix/user_rooms.cc +++ b/matrix/user_rooms.cc @@ -8,6 +8,37 @@ // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. +bool +ircd::m::user::rooms::prefetch() +const +{ + const m::events::state::tuple query + { + user, + "m.room.member"_sv, + m::room::id{}, + -1L, + 0UL + }; + + bool ret{false}; + return m::events::state::for_each(query, [this, &ret] + (const auto &tuple) + { + const auto &[state_key, type, room_id, depth, event_idx] + { + tuple + }; + + assert(type == "m.room.member"); + assert(state_key == user); + ret |= m::membership_prefetch(event_idx); + return true; + }); + + return ret; +} + size_t ircd::m::user::rooms::count() const