im breaking it
Build and Push Docker Images / build-and-push (push) Successful in 25s

This commit is contained in:
2026-02-11 23:06:58 +01:00
parent bfc3f22c29
commit 016e0cee0c
3 changed files with 52 additions and 0 deletions
+27
View File
@@ -3,11 +3,14 @@
import hashlib
import json
import logging
import time
from pathlib import Path
from .config import CHANNELS_FILE, DATA_ROOT, MOVIES_ROOT, SERIES_ROOT
CACHE_DIR = DATA_ROOT / "cache"
# When hash file is missing but cache exists, bootstrap if cache is younger than this (seconds)
CACHE_BOOTSTRAP_MAX_AGE_SEC = 24 * 3600 # 24 hours (covers "restarted within a day")
logger = logging.getLogger(__name__)
@@ -115,6 +118,24 @@ class CacheManager:
if stored != current_hash:
self._write_hash(current_hash)
def _bootstrap_hash_if_recent(self, cache_path: Path) -> bool:
"""If hash is missing but cache file exists and is recent, write hash. Returns True if bootstrapped."""
if self._get_stored_hash() is not None:
return False
if not cache_path.exists():
return False
try:
age = time.time() - cache_path.stat().st_mtime
if age <= CACHE_BOOTSTRAP_MAX_AGE_SEC:
current = get_channels_hash(self._channels_file)
if current is not None and self._ensure_cache_dir():
self._write_hash(current)
logger.info("Cache hash bootstrapped from %s (age %.0fm)", cache_path.name, age / 60)
return True
except OSError:
pass
return False
def get_epg(self) -> str | None:
"""Return cached EPG XML if valid, else None."""
self.invalidate_if_needed()
@@ -127,6 +148,9 @@ class CacheManager:
logger.debug("EPG cache miss: %s does not exist", epg_path)
return None
stored = self._get_stored_hash()
if stored is None:
self._bootstrap_hash_if_recent(epg_path)
stored = self._get_stored_hash()
if stored is None:
logger.debug("EPG cache miss: %s does not exist (hash required)", self._hash_file())
return None
@@ -204,6 +228,9 @@ class CacheManager:
if not path.exists():
return None
stored = self._get_stored_hash()
if stored is None:
self._bootstrap_hash_if_recent(path)
stored = self._get_stored_hash()
if stored != current:
return None
try: