From ff0a6c2ce73950dc90f62334edc11fa30c3db7c3 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 28 Dec 2020 18:59:01 -0800 Subject: [PATCH] ircd::m::user::mitsein: Replace string w/ hash for seen state. --- matrix/user_mitsein.cc | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/matrix/user_mitsein.cc b/matrix/user_mitsein.cc index 74f81c770..b068aa275 100644 --- a/matrix/user_mitsein.cc +++ b/matrix/user_mitsein.cc @@ -71,16 +71,11 @@ const // here we gooooooo :/ ///TODO: ideal: db schema ///TODO: minimally: custom alloc? - std::set> seen; + std::set> seen; return rooms.for_each(membership, rooms::closure_bool{[&membership, &closure, &seen] - (m::room room, const string_view &) + (const m::room &room, const string_view &_membership) { - static const event::fetch::opts fopts - { - event::keys::include {"state_key"} - }; - - room.fopts = &fopts; + assert(_membership == membership); const m::room::members members { room @@ -89,16 +84,20 @@ const return members.for_each(membership, [&seen, &closure] (const user::id &other) { - const auto it + const auto hash { - seen.lower_bound(other) + uint128_t(ircd::hash(other)) + | (uint128_t(ircd::hash(other.host())) << 64) }; - if(it != end(seen) && *it == other) - return true; + const bool inserted + { + seen.emplace(hash).second + }; - seen.emplace_hint(it, std::string{other}); - return closure(m::user{other}); + return inserted? + closure(m::user{other}): + true; }); }}); }