mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 05:04:27 +00:00
Improve outgoing worker
This commit is contained in:
parent
5fc06ccfac
commit
23afd31bff
2 changed files with 13 additions and 2 deletions
|
@ -76,7 +76,9 @@ _RESIZED_CACHE: MutableMapping[tuple[str, int], tuple[bytes, str, Any]] = LFUCac
|
||||||
# TODO(ts):
|
# TODO(ts):
|
||||||
#
|
#
|
||||||
# Next:
|
# 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
|
# - prevent double accept/double follow
|
||||||
# - UI support for updating posts
|
# - UI support for updating posts
|
||||||
# - indieauth tweaks
|
# - indieauth tweaks
|
||||||
|
|
|
@ -4,8 +4,10 @@ import time
|
||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from typing import MutableMapping
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
from cachetools import TTLCache
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
@ -26,6 +28,9 @@ from app.utils.workers import Worker
|
||||||
|
|
||||||
_MAX_RETRIES = 16
|
_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 = Key(config.ID, f"{config.ID}#main-key")
|
||||||
k.load(KEY_PATH.read_text())
|
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)
|
# 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 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=}")
|
logger.info(f"{payload=}")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue