Fix published query, and improve announce dedup

This commit is contained in:
Thomas Sileo 2019-08-17 09:56:46 +02:00
parent ccc8b0a781
commit 612656d75b
2 changed files with 8 additions and 2 deletions

View file

@ -3,6 +3,8 @@ from enum import Enum
from enum import unique from enum import unique
from typing import Any from typing import Any
from typing import Dict from typing import Dict
from typing import List
from typing import Union
from little_boxes import activitypub as ap from little_boxes import activitypub as ap
@ -66,7 +68,10 @@ def in_outbox() -> _SubQuery:
return {"box": Box.OUTBOX.value} return {"box": Box.OUTBOX.value}
def by_type(type_: ap.ActivityType) -> _SubQuery: def by_type(type_: Union[ap.ActivityType, List[ap.ActivityType]]) -> _SubQuery:
if isinstance(type_, list):
return {"type": {"$in": [t.value for t in type_]}}
return {"type": type_.value} return {"type": type_.value}
@ -104,4 +109,4 @@ def upsert(data: Dict[MetaKey, Any]) -> _SubQuery:
def published_after(dt: datetime) -> _SubQuery: def published_after(dt: datetime) -> _SubQuery:
return flag(MetaKey.PUBLISHED, {"gt": ap.format_datetime(dt)}) return flag(MetaKey.PUBLISHED, {"$gt": ap.format_datetime(dt)})

View file

@ -143,6 +143,7 @@ def _announce_set_inbox_flags(activity: ap.Announce, new_meta: _NewMeta) -> None
if not find_one_activity( if not find_one_activity(
{ {
**in_inbox(), **in_inbox(),
**by_type([ap.ActivityType.CRETATE, ap.ActivityType.ANNOUNCE]),
**by_object_id(obj.id), **by_object_id(obj.id),
**flag(MetaKey.STREAM, True), **flag(MetaKey.STREAM, True),
**published_after(datetime.now(timezone.utc) - timedelta(hours=12)), **published_after(datetime.now(timezone.utc) - timedelta(hours=12)),