From 801d0effa96890c0bba7e2ba3048ac1734872800 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 15 Sep 2019 19:56:07 +0200 Subject: [PATCH] Delete old replies --- core/gc.py | 38 ++++++++++++++++++++++++++++++++++++++ core/tasks.py | 4 ++++ 2 files changed, 42 insertions(+) diff --git a/core/gc.py b/core/gc.py index 4939188..1d2229c 100644 --- a/core/gc.py +++ b/core/gc.py @@ -148,6 +148,44 @@ def perform() -> None: # noqa: C901 except Exception: logger.exception(f"failed to process {data!r}") + for data in DB.replies.find( + {_meta(MetaKey.PUBLISHED): {"$lt": d}, "meta.gc_keep": {"$exists": False}} + ).limit(500): + try: + logger.info(f"data={data!r}") + create_count += 1 + remote_id = data["remote_id"] + meta = data["meta"] + + # This activity has been bookmarked, keep it + if meta.get("bookmarked"): + _keep(data) + continue + + obj = ap.parse_activity(data["activity"]) + + # This activity is part of a thread we want to keep, keep it + if obj and in_reply_to and meta.get("thread_root_parent"): + thread_root_parent = meta["thread_root_parent"] + if thread_root_parent.startswith(ID) or thread_root_parent in toi: + _keep(data) + continue + + # This activity was boosted or liked, keep it + if meta.get("boosted") or meta.get("liked"): + _keep(data) + continue + + # Delete the cached attachment + for grid_item in MEDIA_CACHE.fs.find({"remote_id": remote_id}): + MEDIA_CACHE.fs.delete(grid_item._id) + + # Delete the activity + DB.replies.delete_one({"_id": data["_id"]}) + create_deleted += 1 + except Exception: + logger.exception(f"failed to process {data!r}") + after_gc_create = perf_counter() time_to_gc_create = after_gc_create - start logger.info( diff --git a/core/tasks.py b/core/tasks.py index 4278fb7..31bb39b 100644 --- a/core/tasks.py +++ b/core/tasks.py @@ -66,6 +66,10 @@ class Tasks: # TODO(tsileo): log invalid emoji pass + @staticmethod + def ack_reply(reply_iri: str) -> None: + p.push({"reply_iri": reply_iri}, "/task/ack_reply") + @staticmethod def post_to_remote_inbox(payload: str, recp: str) -> None: p.push({"payload": payload, "to": recp}, "/task/post_to_remote_inbox")