queries
queries
¶
Synchronizer-specific database queries.
Classes¶
Functions¶
fetch_cursors_to_sync
async
¶
fetch_cursors_to_sync(
brotr: Brotr, end: int, networks: Sequence[NetworkType]
) -> list[SyncCursor]
Fetch sync cursors for relays on the given networks, ordered by timestamp ascending.
Performs a LEFT JOIN between the relay table and the synchronizer's
cursor state in service_state. Only relays whose network is in
networks are included. Relays without a cursor get a default
cursor (timestamp=0). Relays already synced past end are excluded.
Parameters:
-
brotr(Brotr) –Brotr database interface.
-
end(int) –Upper bound timestamp — relays synced past this are excluded.
-
networks(Sequence[NetworkType]) –Network types to include (e.g. enabled networks from config).
Returns:
-
list[SyncCursor]–List of SyncCursor
-
list[SyncCursor]–ordered by timestamp ascending (oldest first).
Source code in src/bigbrotr/services/synchronizer/queries.py
delete_stale_cursors
async
¶
delete_stale_cursors(brotr: Brotr) -> int
Remove cursor state for relays that no longer exist.
Deletes CURSOR records whose state_key does not match any relay in
the relay table.
Parameters:
Returns:
-
int–Number of deleted rows.
Source code in src/bigbrotr/services/synchronizer/queries.py
insert_event_relays
async
¶
insert_event_relays(
brotr: Brotr, records: list[EventRelay]
) -> int
Batch-insert event-relay junction records.
Splits records into batches respecting BatchConfig.max_size and delegates each chunk to Brotr.insert_event_relay() (cascade mode).
Parameters:
-
brotr(Brotr) –Brotr database interface.
-
records(list[EventRelay]) –EventRelay instances to insert.
Returns:
-
int–Number of new event-relay records inserted.
Source code in src/bigbrotr/services/synchronizer/queries.py
upsert_sync_cursors
async
¶
upsert_sync_cursors(
brotr: Brotr, cursors: Iterable[SyncCursor]
) -> None
Persist multiple sync cursor positions in batched upserts.
Splits cursors into chunks of brotr.config.batch.max_size to
respect database parameter limits.
Parameters:
-
brotr(Brotr) –Brotr database interface.
-
cursors(Iterable[SyncCursor]) –Iterable of SyncCursor instances to persist.