mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd:Ⓜ️:fed::well_known: Move valid cache hit branch before fetch; minor cleanup.
This commit is contained in:
parent
9f38a58402
commit
0f94fe66cb
1 changed files with 17 additions and 19 deletions
|
@ -105,11 +105,6 @@ try
|
|||
content.get<time_t>("ttl", time_t(86400))
|
||||
};
|
||||
|
||||
const string_view cached
|
||||
{
|
||||
data(buf), move(buf, json::string(content["m.server"]))
|
||||
};
|
||||
|
||||
const system_point expires
|
||||
{
|
||||
origin_server_ts + ttl
|
||||
|
@ -120,24 +115,16 @@ try
|
|||
ircd::now<system_point>() > expires
|
||||
};
|
||||
|
||||
const string_view cached
|
||||
{
|
||||
data(buf), move(buf, json::string(content["m.server"]))
|
||||
};
|
||||
|
||||
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
|
||||
// when a network query needs to be made, otherwise we can return the
|
||||
// cached value. If the network query fails, this value is still defaulted
|
||||
// as the origin string to return and we'll also cache that too.
|
||||
const string_view delegated
|
||||
{
|
||||
expired || !valid?
|
||||
fetch(buf + size(cached), origin):
|
||||
cached
|
||||
};
|
||||
|
||||
// Branch on valid cache hit to return result.
|
||||
if(valid && !expired)
|
||||
{
|
||||
|
@ -151,9 +138,20 @@ try
|
|||
timef(tmbuf, expires, localtime),
|
||||
};
|
||||
|
||||
return delegated;
|
||||
return 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
|
||||
// when a network query needs to be made, otherwise we can return the
|
||||
// cached value. If the network query fails, this value is still defaulted
|
||||
// as the origin string to return and we'll also cache that too.
|
||||
const string_view delegated
|
||||
{
|
||||
fetch(buf + size(cached), origin)
|
||||
};
|
||||
|
||||
// Conditions for valid expired cache hit w/ failure to reacquire.
|
||||
const bool fallback
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue