aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/ops/apps.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/ops/apps.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/ops/apps.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/ops/apps.py b/packages/meshbay-node/src/meshbay_node/ops/apps.py
index 0e4f6dd..fbd984d 100644
--- a/packages/meshbay-node/src/meshbay_node/ops/apps.py
+++ b/packages/meshbay-node/src/meshbay_node/ops/apps.py
@@ -53,6 +53,13 @@ async def set_tmdb_config(state: dict, token: str | None = None,
`language`.
"""
roster = _roster(state)
+ # Whether the *language* actually changes decides whether the cached
+ # fiches must go (below) — read the old value before overwriting it.
+ # "" (default/English) and None (unset) are the same language here.
+ language_changed = False
+ if language is not None:
+ _, old_language = await roster.tmdb_config()
+ language_changed = (language or None) != (old_language or None)
await roster.set_tmdb_config(token, language, set_by=state.get("node_user_id", ""))
# `token=None` means "leave whatever was there" (§ set_tmdb_config's own
# docstring) — so the customized flag only changes when a value (a real
@@ -61,6 +68,19 @@ async def set_tmdb_config(state: dict, token: str | None = None,
state["tmdb_token_customized"] = bool(token)
if language is not None:
state["tmdb_language"] = language
+ # A cached TMDB fiche is stored under its tmdb_id alone and carries no note
+ # of the language it was fetched in (there is only one node-wide language),
+ # so changing the language leaves every fiche stale for its 30-day TTL.
+ # Drop the metadata cache here so the next media_meta_req refetches in the
+ # new language — this is what makes the setting take on a library that was
+ # already browsed, instead of the operator having to find a cache to clear.
+ # The matches (file_tmdb) are language-independent and kept.
+ if language_changed:
+ media_cache = state.get("media_cache")
+ if media_cache is not None:
+ removed = await media_cache.clear_tmdb_metadata()
+ log.info("TMDB language changed to %s: cleared %d cached fiche(s)",
+ language or "(default)", removed)
log.info("TMDB config: custom_token=%s language=%s",
bool(token), language or state.get("tmdb_language", ""))
return {