Improve outgoing worker
parent
5fc06ccfac
commit
23afd31bff
|
@ -76,7 +76,9 @@ _RESIZED_CACHE: MutableMapping[tuple[str, int], tuple[bytes, str, Any]] = LFUCac
|
|||
# TODO(ts):
|
||||
#
|
||||
# Next:
|
||||
# - allow to manually approve follow requests
|
||||
# - Add a TTL cache for the LD sig (no need to re-compute)
|
||||
# - only show 10 most recent threads in DMs
|
||||
# - custom CSS for disabled button (e.g. sharing on a direct post)
|
||||
# - prevent double accept/double follow
|
||||
# - UI support for updating posts
|
||||
# - indieauth tweaks
|
||||
|
|
|
@ -4,8 +4,10 @@ import time
|
|||
import traceback
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
from typing import MutableMapping
|
||||
|
||||
import httpx
|
||||
from cachetools import TTLCache
|
||||
from loguru import logger
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy import select
|
||||
|
@ -26,6 +28,9 @@ from app.utils.workers import Worker
|
|||
|
||||
_MAX_RETRIES = 16
|
||||
|
||||
_LD_SIG_CACHE: MutableMapping[str, ap.RawObject] = TTLCache(maxsize=5, ttl=60 * 5)
|
||||
|
||||
|
||||
k = Key(config.ID, f"{config.ID}#main-key")
|
||||
k.load(KEY_PATH.read_text())
|
||||
|
||||
|
@ -237,7 +242,11 @@ async def process_next_outgoing_activity(
|
|||
]:
|
||||
# But only if the object is public (to help with deniability/privacy)
|
||||
if next_activity.outbox_object.visibility == ap.VisibilityEnum.PUBLIC: # type: ignore # noqa: E501
|
||||
ldsig.generate_signature(payload, k)
|
||||
if p := _LD_SIG_CACHE.get(payload["id"]):
|
||||
payload = p
|
||||
else:
|
||||
ldsig.generate_signature(payload, k)
|
||||
_LD_SIG_CACHE[payload["id"]] = payload
|
||||
|
||||
logger.info(f"{payload=}")
|
||||
|
||||
|
|
Loading…
Reference in New Issue