INNER CODE UNIT · Python
_ban_multiplier_for
BlessedRebuS/Krawl · src/database/core.py:50
def _ban_multiplier_for(total_violations: int) -> int:
"""Exponential backoff multiplier, clamped to avoid int4 overflow."""
exponent = min(max(total_violations - 1, 0), MAX_BAN_EXPONENT)
return 2**exponent
# ── Access-log write buffer (scalable mode) ──────────────────────────
# Instead of INSERT-per-request over the network, access log entries are
# buffered in memory and flushed in bulk every few seconds by a background task.
# IP stats counters are still updated synchronously (needed for ban checks).
# Statement size, not a per-flush ceiling: the flush loops until drained.
_FLUSH_BATCH_SIZE = 200
# Two ceilings, because a row count is not a memory bound. Entries carry
# `raw_request`, capped at MAX_RAW_REQUEST (16 KiB), so 50k rows is anywhere
# between ~60 MiB and ~800 MiB depending on what the traffic looks like — and
# an attack flood is exactly the traffic that fills the buffer with large