INNER CODE UNIT · Python
_pop_batch
BlessedRebuS/Krawl · src/database/core.py:443
def _pop_batch(self, n: int) -> list[dict]:
"""Remove up to n entries from the front of the write buffer."""
global _buffer_bytes
with _write_lock:
batch = [_write_buffer.popleft() for _ in range(min(len(_write_buffer), n))]
_buffer_bytes -= sum(_entry_bytes(e) for e in batch)
return batch
def flush_access_log_buffer(self, max_rows: int = 50_000) -> int:
"""
Bulk-insert buffered access log entries into the database.
Drains in _FLUSH_BATCH_SIZE statements until empty, so the flush rate
follows arrival rate. max_rows caps the work one run may do.
Returns the number of entries flushed.
"""
total = 0