From cffe801148901592250a28453f4a12aaca240338 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 29 Apr 2020 02:36:12 -0700 Subject: [PATCH] ircd::m::fed: Simplify cached result copy and test. --- matrix/fed.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/matrix/fed.cc b/matrix/fed.cc index d7775892c..766bdb5f1 100644 --- a/matrix/fed.cc +++ b/matrix/fed.cc @@ -1733,6 +1733,11 @@ try ircd::now() > expires }; + const bool valid + { + !empty(cached) + }; + // Crucial value that will provide us with a return string for this // function in any case. This is obtained by either using the value // found in cache or making a network query for a new value. expired=true @@ -1741,7 +1746,7 @@ try // as the origin string to return and we'll also cache that too. const string_view delegated { - empty(cached) || expired? + expired || !valid? fetch_well_known(buf, origin): // Move the returned string to the front of the buffer; this overwrites @@ -1753,14 +1758,14 @@ try }; // Branch on valid cache hit to return result. - if(!empty(cached) && !expired) + if(valid && !expired) { char tmbuf[48]; log::debug { well_known_log, "%s found in cache delegated to %s event_idx:%u expires %s", origin, - delegated, + cached, event_idx, timef(tmbuf, expires, localtime), }; @@ -1769,7 +1774,7 @@ try } // Branch on query failure to fallback on existing expired record - if(expired && !empty(cached) && delegated == origin) + if(expired && valid && delegated == origin) { char tmbuf[48]; log::debug @@ -1781,10 +1786,7 @@ try timef(tmbuf, expires, localtime), }; - return string_view - { - data(buf), move(buf, cached) - }; + return delegated; } // Any time the well-known result is the same as the origin (that