cache manager
Build and Push Docker Images / build-and-push (push) Successful in 16s

This commit is contained in:
2026-02-11 21:39:39 +01:00
parent 9f87297d35
commit fecd8389e9
5 changed files with 237 additions and 19 deletions
+12 -2
View File
@@ -48,16 +48,23 @@ def schedule_epoch_utc() -> datetime:
class EPGBuilder:
"""Builds XMLTV EPG for all channels."""
def __init__(self, schedule_builder, tmdb_client, channel_repo):
def __init__(self, schedule_builder, tmdb_client, channel_repo, cache_manager=None):
self._schedule = schedule_builder
self._tmdb = tmdb_client
self._channels = channel_repo
self._cache = cache_manager
def build_xml(self) -> str:
"""
Build XMLTV EPG for all channels. Schedule repeats from midnight UTC.
Programmes generated for EPG_TIMESPAN_DAYS.
"""
if self._cache:
cached = self._cache.get_epg()
if cached is not None:
logger.debug("EPG served from cache")
return cached
epg_start = time.monotonic()
channels = self._channels.get_all()
if not channels:
@@ -181,7 +188,10 @@ class EPGBuilder:
ET.indent(root, space=" ")
epg_elapsed = time.monotonic() - epg_start
logger.info("EPG build finished in %.1fs (%s programmes total)", epg_elapsed, total_programmes)
return (
xml = (
'<?xml version="1.0" encoding="UTF-8"?>\n'
+ ET.tostring(root, encoding="unicode", default_namespace=None)
)
if self._cache:
self._cache.set_epg(xml)
return xml