Improve outgoing worker

main
Thomas Sileo 2022-08-11 23:10:24 +02:00
parent 5fc06ccfac
commit 23afd31bff
2 changed files with 13 additions and 2 deletions

View File

@ -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

View File

@ -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
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=}")