queries
queries
¶
Shared database query utilities for BigBrotr services.
Provides batch-insert helpers and cross-service state operations that
are used by more than one service's queries module.
See Also
Brotr: Database facade that provides
fetch(), fetchrow(), fetchval(), execute(),
and transaction() methods used by every query function.
ServiceState: Dataclass
used for candidate and cursor records in service_state.
Classes¶
Functions¶
batched_insert
async
¶
batched_insert(
brotr: Brotr,
records: list[_T],
method: Callable[[list[_T]], Awaitable[int]],
) -> int
Split records into batches of brotr.config.batch.max_size and
call method on each chunk, returning the total count.
Source code in src/bigbrotr/services/common/queries.py
upsert_service_states
async
¶
upsert_service_states(
brotr: Brotr, records: list[ServiceState]
) -> int
Batch-upsert service state records.
Splits records into batches respecting BatchConfig.max_size and delegates each chunk to Brotr.upsert_service_state().
Services use this to persist operational state (cursors, monitoring markers, candidate failure counters) without worrying about batch size limits.
Parameters:
-
brotr(Brotr) –Brotr database interface.
-
records(list[ServiceState]) –ServiceState instances to upsert.
Returns:
-
int–Number of records upserted.
Source code in src/bigbrotr/services/common/queries.py
insert_relays_as_candidates
async
¶
Insert new validation candidates, skipping known relays and duplicates.
Filters out URLs that already exist in the relay table or as
pending candidates in service_state, then persists only genuinely
new records. Existing candidates retain their current state (e.g.
failures counter is never reset).
Called by Seeder and Finder to register newly discovered relay URLs for validation.
Parameters:
-
brotr(Brotr) –Brotr database interface.
-
relays(list[Relay]) –Relay objects to register as candidates.
Returns:
-
int–Number of candidate records actually inserted.