Files
2026-10-06 12:32:26 +03:00

36 lines
1.2 KiB
Python

"""Acquisition identity shared unchanged by every pipeline stage."""
from __future__ import annotations
from collections.abc import Iterable, Mapping, Sequence
from typing import Protocol, TypeVar
class CollectionIdentity(Protocol):
@property
def collection_id(self) -> int: ...
@property
def capture_start_ns(self) -> int: ...
TCollection = TypeVar("TCollection", bound=CollectionIdentity)
def collection_key(collection: CollectionIdentity) -> tuple[int, int]:
return collection.collection_id, collection.capture_start_ns
def index_collections(collections: Iterable[TCollection]) -> dict[tuple[int, int], TCollection]:
return {collection_key(collection): collection for collection in collections}
def history_collection_removed(
collection: CollectionIdentity, clear_before_ns: int, removed: Sequence[Mapping[str, int]],
) -> bool:
"""Apply a capture-time cutoff and exact acquisition deletions to late results."""
return (bool(clear_before_ns) and collection.capture_start_ns <= clear_before_ns) or any(
collection_key(collection) == (target["collection_id"], target["capture_start_ns"])
for target in removed
)