mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-11-15 03:04:28 +00:00
Fix the media URL cache
This commit is contained in:
parent
777b086d4f
commit
f3dc4995f1
2 changed files with 14 additions and 4 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
cachetools
|
||||||
poussetaches
|
poussetaches
|
||||||
python-dateutil
|
python-dateutil
|
||||||
libsass
|
libsass
|
||||||
|
|
|
@ -2,7 +2,6 @@ import logging
|
||||||
import urllib
|
import urllib
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import timezone
|
from datetime import timezone
|
||||||
from functools import lru_cache
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import bleach
|
import bleach
|
||||||
|
@ -10,6 +9,7 @@ import emoji_unicode
|
||||||
import flask
|
import flask
|
||||||
import html2text
|
import html2text
|
||||||
import timeago
|
import timeago
|
||||||
|
from cachetools import LRUCache
|
||||||
from little_boxes import activitypub as ap
|
from little_boxes import activitypub as ap
|
||||||
from little_boxes.activitypub import _to_list
|
from little_boxes.activitypub import _to_list
|
||||||
from little_boxes.errors import ActivityGoneError
|
from little_boxes.errors import ActivityGoneError
|
||||||
|
@ -232,11 +232,20 @@ def get_total_answers_count(obj, meta):
|
||||||
return cnt
|
return cnt
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(512)
|
_FILE_URL_CACHE = LRUCache(4096)
|
||||||
|
|
||||||
|
|
||||||
def _get_file_url(url, size, kind) -> str:
|
def _get_file_url(url, size, kind) -> str:
|
||||||
doc = MEDIA_CACHE.get_file(url, size, kind)
|
k = (url, size, kind)
|
||||||
|
cached = _FILE_URL_CACHE.get(k)
|
||||||
|
if cached:
|
||||||
|
return cached
|
||||||
|
|
||||||
|
doc = MEDIA_CACHE.get_file(*k)
|
||||||
if doc:
|
if doc:
|
||||||
return f"/media/{str(doc._id)}"
|
out = f"/media/{str(doc._id)}"
|
||||||
|
_FILE_URL_CACHE[k] = out
|
||||||
|
return out
|
||||||
|
|
||||||
# MEDIA_CACHE.cache(url, kind)
|
# MEDIA_CACHE.cache(url, kind)
|
||||||
_logger.error(f"cache not available for {url}/{size}/{kind}")
|
_logger.error(f"cache not available for {url}/{size}/{kind}")
|
||||||
|
|
Loading…
Reference in a new issue