Move history archive max timestamp query into repository

This commit is contained in:
2026-04-15 21:18:44 +02:00
parent cdb0c3681e
commit 56f03f39c7
4 changed files with 38 additions and 7 deletions

View File

@@ -28,7 +28,7 @@ from app.models.history import (
IpTimelineEvent,
)
from app.repositories import fail2ban_db_repo
from app.repositories.history_archive_repo import archive_ban_event
from app.repositories.history_archive_repo import archive_ban_event, get_max_timeofban
from app.services.fail2ban_metadata_service import default_fail2ban_metadata_service
from app.utils.fail2ban_db_utils import parse_data_json, ts_to_iso
@@ -67,11 +67,7 @@ _HISTORY_SYNC_BACKFILL_WINDOW: int = 648000
async def _get_last_archive_ts(db: aiosqlite.Connection) -> int | None:
"""Return the most recent archived ban timestamp, or ``None`` if empty."""
async with db.execute("SELECT MAX(timeofban) FROM history_archive") as cur:
row = await cur.fetchone()
if row is None or row[0] is None:
return None
return int(row[0])
return await get_max_timeofban(db)
async def sync_from_fail2ban_db(