Fix snapshot read path sqlite lock

This commit is contained in:
devRaGonSa
2026-03-24 11:55:47 +01:00
parent c7c9865075
commit e43e22dc0e
2 changed files with 14 additions and 6 deletions

View File

@@ -9,16 +9,20 @@ from pathlib import Path
from .config import get_storage_path from .config import get_storage_path
from .historical_models import HistoricalSnapshotRecord from .historical_models import HistoricalSnapshotRecord
from .historical_snapshots import validate_snapshot_identity from .historical_snapshots import validate_snapshot_identity
from .historical_storage import initialize_historical_storage
SNAPSHOT_DIRECTORY_NAME = "snapshots" SNAPSHOT_DIRECTORY_NAME = "snapshots"
def resolve_historical_snapshot_storage_path(*, db_path: Path | None = None) -> Path:
"""Resolve the snapshot directory location without touching SQLite state."""
resolved_db_path = db_path or get_storage_path()
return resolved_db_path.parent / SNAPSHOT_DIRECTORY_NAME
def initialize_historical_snapshot_storage(*, db_path: Path | None = None) -> Path: def initialize_historical_snapshot_storage(*, db_path: Path | None = None) -> Path:
"""Create the snapshot directory used by precomputed historical payloads.""" """Create the snapshot directory used by precomputed historical payloads."""
resolved_db_path = initialize_historical_storage(db_path=db_path or get_storage_path()) snapshots_root = resolve_historical_snapshot_storage_path(db_path=db_path)
snapshots_root = resolved_db_path.parent / SNAPSHOT_DIRECTORY_NAME
snapshots_root.mkdir(parents=True, exist_ok=True) snapshots_root.mkdir(parents=True, exist_ok=True)
return snapshots_root return snapshots_root
@@ -144,7 +148,7 @@ def get_historical_snapshot(
) -> dict[str, object] | None: ) -> dict[str, object] | None:
"""Return one persisted snapshot and decoded payload, if present.""" """Return one persisted snapshot and decoded payload, if present."""
validate_snapshot_identity(snapshot_type=snapshot_type, metric=metric) validate_snapshot_identity(snapshot_type=snapshot_type, metric=metric)
snapshots_root = initialize_historical_snapshot_storage(db_path=db_path) snapshots_root = resolve_historical_snapshot_storage_path(db_path=db_path)
snapshot_path = _build_snapshot_path( snapshot_path = _build_snapshot_path(
snapshots_root=snapshots_root, snapshots_root=snapshots_root,
server_key=server_key, server_key=server_key,
@@ -175,7 +179,9 @@ def list_historical_snapshots(
db_path: Path | None = None, db_path: Path | None = None,
) -> list[dict[str, object]]: ) -> list[dict[str, object]]:
"""List persisted snapshots for validation and operational inspection.""" """List persisted snapshots for validation and operational inspection."""
snapshots_root = initialize_historical_snapshot_storage(db_path=db_path) snapshots_root = resolve_historical_snapshot_storage_path(db_path=db_path)
if not snapshots_root.exists():
return []
if snapshot_type: if snapshot_type:
validate_snapshot_identity(snapshot_type=snapshot_type) validate_snapshot_identity(snapshot_type=snapshot_type)

View File

@@ -1570,8 +1570,10 @@ def list_monthly_mvp_ranking(
def _connect(db_path: Path) -> sqlite3.Connection: def _connect(db_path: Path) -> sqlite3.Connection:
connection = sqlite3.connect(db_path) connection = sqlite3.connect(db_path, timeout=30.0)
connection.row_factory = sqlite3.Row connection.row_factory = sqlite3.Row
connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout = 30000")
return connection return connection