Rework stale returns
This commit is contained in:
parent
3ab95e5d65
commit
688f0d17d8
1 changed files with 3 additions and 4 deletions
|
@ -224,7 +224,7 @@ def preview_url(
|
||||||
for result in results:
|
for result in results:
|
||||||
# find the one with the closest timestamp
|
# find the one with the closest timestamp
|
||||||
metadata, _ts = result
|
metadata, _ts = result
|
||||||
created_at = datetime.datetime.fromtimestamp(_ts)
|
created_at = datetime.datetime.fromtimestamp(_ts - 86400)
|
||||||
if ts is None or created_at <= datetime.datetime.fromtimestamp(ts):
|
if ts is None or created_at <= datetime.datetime.fromtimestamp(ts):
|
||||||
logging.debug("Optimal cache hit for %r", url)
|
logging.debug("Optimal cache hit for %r", url)
|
||||||
return json.loads(metadata)
|
return json.loads(metadata)
|
||||||
|
@ -233,12 +233,11 @@ def preview_url(
|
||||||
# No close matches, get the latest one
|
# No close matches, get the latest one
|
||||||
metadata, _ts = results[-1]
|
metadata, _ts = results[-1]
|
||||||
created_at = datetime.datetime.fromtimestamp(_ts)
|
created_at = datetime.datetime.fromtimestamp(_ts)
|
||||||
# If the latest one is more than a week old, re-fetch. Otherwise, return.
|
if (datetime.datetime.now() - created_at).days <= 7:
|
||||||
if ts is None or created_at < (datetime.datetime.now() - datetime.timedelta(days=7)):
|
|
||||||
logging.debug("Stale cache hit for %r", url)
|
logging.debug("Stale cache hit for %r", url)
|
||||||
return json.loads(metadata)
|
return json.loads(metadata)
|
||||||
else:
|
else:
|
||||||
logging.debug("Cache miss for %r", url)
|
logging.debug("Stale cache miss for %r", url)
|
||||||
else:
|
else:
|
||||||
logging.debug("Full cache miss for %r", url)
|
logging.debug("Full cache miss for %r", url)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue