mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-11-15 03:04:28 +00:00
Make a query before spawning cache actor task
This commit is contained in:
parent
075d3c3742
commit
2a726b7dfb
3 changed files with 13 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
import pymongo
|
import pymongo
|
||||||
|
|
||||||
from config import DB
|
from config import DB
|
||||||
|
from config import MEDIA_CACHE
|
||||||
from core.meta import MetaKey
|
from core.meta import MetaKey
|
||||||
from core.meta import _meta
|
from core.meta import _meta
|
||||||
|
|
||||||
|
@ -73,3 +74,6 @@ def create_indexes():
|
||||||
("meta.deleted", pymongo.ASCENDING),
|
("meta.deleted", pymongo.ASCENDING),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# For the is_actor_icon_cached query
|
||||||
|
MEDIA_CACHE.fs._GridFS__files.create_index([("url", 1), ("kind", 1)])
|
||||||
|
|
|
@ -4,6 +4,7 @@ from datetime import timezone
|
||||||
|
|
||||||
from poussetaches import PousseTaches
|
from poussetaches import PousseTaches
|
||||||
|
|
||||||
|
from config import MEDIA_CACHE
|
||||||
from utils import parse_datetime
|
from utils import parse_datetime
|
||||||
|
|
||||||
p = PousseTaches(
|
p = PousseTaches(
|
||||||
|
@ -25,7 +26,10 @@ class Tasks:
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cache_actor_icon(icon_url: str, actor_iri: str):
|
def cache_actor_icon(icon_url: str, actor_iri: str) -> None:
|
||||||
|
if MEDIA_CACHE.is_actor_icon_cached(icon_url):
|
||||||
|
return None
|
||||||
|
|
||||||
p.push({"icon_url": icon_url, "actor_iri": actor_iri}, "/task/cache_actor_icon")
|
p.push({"icon_url": icon_url, "actor_iri": actor_iri}, "/task/cache_actor_icon")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -136,8 +136,11 @@ class MediaCache(object):
|
||||||
remote_id=remote_id,
|
remote_id=remote_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def is_actor_icon_cached(self, url: str) -> bool:
|
||||||
|
return bool(self.fs.find_one({"url": url, "kind": Kind.ACTOR_ICON.value}))
|
||||||
|
|
||||||
def cache_actor_icon(self, url: str) -> None:
|
def cache_actor_icon(self, url: str) -> None:
|
||||||
if self.fs.find_one({"url": url, "kind": Kind.ACTOR_ICON.value}):
|
if self.is_actor_icon_cached(url):
|
||||||
return
|
return
|
||||||
i = load(url, self.user_agent)
|
i = load(url, self.user_agent)
|
||||||
for size in [50, 80]:
|
for size in [50, 80]:
|
||||||
|
|
Loading…
Reference in a new issue