From 4b60068809b500c1a040644d1d9663ba62fa8efb Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 11 Nov 2020 15:48:05 -0800 Subject: [PATCH] ircd::m::room::aliases: Improve aliases cache::get related. --- matrix/room_aliases.cc | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/matrix/room_aliases.cc b/matrix/room_aliases.cc index bf73065f9..bf185dcc9 100644 --- a/matrix/room_aliases.cc +++ b/matrix/room_aliases.cc @@ -222,39 +222,32 @@ ircd::m::room::aliases::cache::get(std::nothrow_t, getidx(alias) }; - if(!event_idx) + const bool expired + { + !my_host(alias.host()) && (!event_idx || cache::expired(event_idx)) + }; + + if(!event_idx || expired) { if(my_host(alias.host())) return false; + if(expired) + log::dwarning + { + log, "Cached alias %s expired age:%ld ttl:%ld", + string_view{alias}, + cache::age(event_idx).count(), + milliseconds(seconds(alias_cache_ttl)).count(), + }; + if(!fetch(std::nothrow, alias, alias.host())) return false; - event_idx = getidx(alias); + if(!(event_idx = getidx(alias))) + return false; } - const bool expired - { - !my_host(alias.host()) && cache::expired(event_idx) - }; - - if(expired) - { - log::dwarning - { - log, "Cached alias %s expired age:%ld ttl:%ld", - string_view{alias}, - cache::age(event_idx).count(), - milliseconds(seconds(alias_cache_ttl)).count(), - }; - - fetch(std::nothrow, alias, alias.host()); - event_idx = getidx(alias); - } - - if(!event_idx) - return false; - bool ret{false}; m::get(std::nothrow, event_idx, "content", [&closure, &ret] (const json::object &content)