INNER CODE UNIT · Python
_buffer_access_log_entry
BlessedRebuS/Krawl · src/database/core.py:96
def _buffer_access_log_entry(**kwargs) -> None:
"""Append an access-log entry to the in-memory write buffer.
Evicts oldest-first when either ceiling is hit, and counts the losses, so
a flush task that falls behind degrades into dropped rows rather than an
OOM kill.
"""
global _dropped_rows, _buffer_bytes
kwargs["_buffered_at"] = datetime.now()
size = _entry_bytes(kwargs)
with _write_lock:
if len(_write_buffer) == _MAX_BUFFER_ROWS:
# maxlen evicts from the left on append; account for it ourselves.
_buffer_bytes -= _entry_bytes(_write_buffer[0])
_dropped_rows += 1
_write_buffer.append(kwargs)
_buffer_bytes += size