Delete old replies
This commit is contained in:
parent
5c8a037340
commit
801d0effa9
2 changed files with 42 additions and 0 deletions
38
core/gc.py
38
core/gc.py
|
@ -148,6 +148,44 @@ def perform() -> None: # noqa: C901
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception(f"failed to process {data!r}")
|
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()
|
after_gc_create = perf_counter()
|
||||||
time_to_gc_create = after_gc_create - start
|
time_to_gc_create = after_gc_create - start
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|
|
@ -66,6 +66,10 @@ class Tasks:
|
||||||
# TODO(tsileo): log invalid emoji
|
# TODO(tsileo): log invalid emoji
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def ack_reply(reply_iri: str) -> None:
|
||||||
|
p.push({"reply_iri": reply_iri}, "/task/ack_reply")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def post_to_remote_inbox(payload: str, recp: str) -> None:
|
def post_to_remote_inbox(payload: str, recp: str) -> None:
|
||||||
p.push({"payload": payload, "to": recp}, "/task/post_to_remote_inbox")
|
p.push({"payload": payload, "to": recp}, "/task/post_to_remote_inbox")
|
||||||
|
|
Loading…
Reference in a new issue