queries
queries
¶
Finder-specific database queries.
Classes¶
Functions¶
fetch_cursors_to_find
async
¶
fetch_cursors_to_find(brotr: Brotr) -> list[FinderCursor]
Fetch all relays with their event-scanning cursor position.
Performs a single LEFT JOIN between the relay table and
service_state (filtered on finder / cursor), returning an
FinderCursor for
every relay. Relays without a stored cursor get default values
(timestamp=0, scan from beginning).
Results are ordered by (timestamp, id) ascending so that relays
with the least scanning progress are processed first.
Parameters:
Returns:
-
list[FinderCursor]–List of
-
list[FinderCursor]– -
list[FinderCursor]–one per relay in the database, ordered by
(timestamp, id).
Source code in src/bigbrotr/services/finder/queries.py
scan_event_relay
async
¶
scan_event_relay(
brotr: Brotr, cursor: FinderCursor, limit: int
) -> list[dict[str, Any]]
Scan event-relay rows for a specific relay, cursor-paginated.
Uses a composite cursor (timestamp, id) for deterministic
pagination that handles ties in seen_at. When the cursor has
timestamp=0 (default), scanning starts from the beginning.
Parameters:
-
brotr(Brotr) –The Brotr database facade.
-
cursor(FinderCursor) –FinderCursor with relay URL and pagination position.
-
limit(int) –Maximum rows per batch.
Returns:
-
list[dict[str, Any]]–List of dicts with all event columns plus
seen_atfrom the -
list[dict[str, Any]]–event_relayjunction.
Source code in src/bigbrotr/services/finder/queries.py
fetch_api_checkpoints
async
¶
fetch_api_checkpoints(
brotr: Brotr, urls: list[str]
) -> list[ApiCheckpoint]
Fetch per-source API checkpoints, returning one per URL.
Returns an ApiCheckpoint
for every URL in urls. URLs with a stored CHECKPOINT record get
their persisted timestamp; URLs without a record get a default
checkpoint with timestamp=0 (immediately eligible for refresh).
Records that cannot be parsed (missing or non-integer timestamp)
are treated as missing and receive the default.
Parameters:
Returns:
-
list[ApiCheckpoint]–List of ApiCheckpoint,
-
list[ApiCheckpoint]–one per input URL, in the same order.
Source code in src/bigbrotr/services/finder/queries.py
upsert_api_checkpoints
async
¶
upsert_api_checkpoints(
brotr: Brotr, checkpoints: list[ApiCheckpoint]
) -> None
Persist per-source API timestamps as CHECKPOINT records.
Parameters:
-
brotr(Brotr) –The Brotr database facade.
-
checkpoints(list[ApiCheckpoint]) –ApiCheckpoint instances to persist.
Source code in src/bigbrotr/services/finder/queries.py
upsert_finder_cursors
async
¶
upsert_finder_cursors(
brotr: Brotr, cursors: Iterable[FinderCursor]
) -> None
Persist multiple scan cursor positions in a single batch upsert.
Cursors at default position (timestamp=0) are silently skipped.
Parameters:
-
brotr(Brotr) –The Brotr database facade.
-
cursors(Iterable[FinderCursor]) –Iterable of FinderCursor instances to persist.
Source code in src/bigbrotr/services/finder/queries.py
delete_stale_cursors
async
¶
delete_stale_cursors(brotr: Brotr) -> int
Delete CURSOR records whose relay no longer exists in the relay table.
Parameters:
Returns:
-
int–Number of stale cursor records deleted.
Source code in src/bigbrotr/services/finder/queries.py
delete_stale_api_checkpoints
async
¶
delete_stale_api_checkpoints(
brotr: Brotr, active_urls: list[str]
) -> int
Delete CHECKPOINT records for API sources no longer in the config.
Parameters:
-
brotr(Brotr) –The Brotr database facade.
-
active_urls(list[str]) –Currently configured source URLs to keep.
Returns:
-
int–Number of stale checkpoint records deleted.