Debug share dedup

This commit is contained in:
Thomas Sileo 2022-08-27 11:21:42 +02:00
parent 7283ba134c
commit 00004a3239

View file

@ -1655,18 +1655,23 @@ async def _handle_announce_activity(
# stream if it's not already there, from an followed actor # stream if it's not already there, from an followed actor
# and if we haven't seen it recently # and if we haven't seen it recently
skip_delta = timedelta(hours=1) skip_delta = timedelta(hours=1)
if ( delta_from_original = now() - as_utc(
now() - as_utc(relates_to_inbox_object.ap_published_at) # type: ignore relates_to_inbox_object.ap_published_at # type: ignore
) < skip_delta or ( )
if (delta_from_original) < skip_delta or (
dup_count := (
await db_session.scalar( await db_session.scalar(
select(func.count(func.distinct(models.InboxObject.id))).where( select(func.count(models.InboxObject.id)).where(
models.InboxObject.ap_type == "Announce", models.InboxObject.ap_type == "Announce",
models.InboxObject.ap_published_at > now() - skip_delta, models.InboxObject.ap_published_at > now() - skip_delta,
models.InboxObject.relates_to_inbox_object_id models.InboxObject.relates_to_inbox_object_id
== relates_to_inbox_object.id, == relates_to_inbox_object.id,
models.InboxObject.is_hidden_from_stream.is_(False),
)
) )
) )
) > 0: ) > 0:
logger.info(f"Deduping Announce {delta_from_original=}/{dup_count=}")
announce_activity.is_hidden_from_stream = True announce_activity.is_hidden_from_stream = True
else: else:
announce_activity.is_hidden_from_stream = not is_from_following announce_activity.is_hidden_from_stream = not is_from_following