From 00004a3239a2527ab8bddad73875b7681cdffd01 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 27 Aug 2022 11:21:42 +0200 Subject: [PATCH] Debug share dedup --- app/boxes.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/app/boxes.py b/app/boxes.py index 06a5f53..8b25170 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -1655,18 +1655,23 @@ async def _handle_announce_activity( # stream if it's not already there, from an followed actor # and if we haven't seen it recently skip_delta = timedelta(hours=1) - if ( - now() - as_utc(relates_to_inbox_object.ap_published_at) # type: ignore - ) < skip_delta or ( - await db_session.scalar( - select(func.count(func.distinct(models.InboxObject.id))).where( - models.InboxObject.ap_type == "Announce", - models.InboxObject.ap_published_at > now() - skip_delta, - models.InboxObject.relates_to_inbox_object_id - == relates_to_inbox_object.id, + delta_from_original = now() - as_utc( + relates_to_inbox_object.ap_published_at # type: ignore + ) + if (delta_from_original) < skip_delta or ( + dup_count := ( + await db_session.scalar( + select(func.count(models.InboxObject.id)).where( + models.InboxObject.ap_type == "Announce", + models.InboxObject.ap_published_at > now() - skip_delta, + models.InboxObject.relates_to_inbox_object_id + == relates_to_inbox_object.id, + models.InboxObject.is_hidden_from_stream.is_(False), + ) ) ) ) > 0: + logger.info(f"Deduping Announce {delta_from_original=}/{dup_count=}") announce_activity.is_hidden_from_stream = True else: announce_activity.is_hidden_from_stream = not is_from_following