mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2026-04-06 05:07:16 +02:00
fix: invalidate CK price cache after GitHub download so prices load without restart
Some checks are pending
CI / build (push) Waiting to run
Some checks are pending
CI / build (push) Waiting to run
This commit is contained in:
parent
6ecd45117f
commit
33aced3c97
9 changed files with 39 additions and 4 deletions
|
|
@ -13,7 +13,7 @@
|
||||||
# HOST=0.0.0.0 # Uvicorn bind host (only when APP_MODE=web).
|
# HOST=0.0.0.0 # Uvicorn bind host (only when APP_MODE=web).
|
||||||
# PORT=8080 # Uvicorn port.
|
# PORT=8080 # Uvicorn port.
|
||||||
# WORKERS=1 # Uvicorn worker count.
|
# WORKERS=1 # Uvicorn worker count.
|
||||||
APP_VERSION=v4.6.2 # Matches dockerhub compose.
|
APP_VERSION=v4.6.3 # Matches dockerhub compose.
|
||||||
|
|
||||||
############################
|
############################
|
||||||
# Theming
|
# Theming
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ _No unreleased changes yet_
|
||||||
### Removed
|
### Removed
|
||||||
_No unreleased changes yet_
|
_No unreleased changes yet_
|
||||||
|
|
||||||
|
## [4.6.3] - 2026-04-04
|
||||||
|
### Fixed
|
||||||
|
- **CK prices not loading after GitHub cache download**: The `PriceService` singleton sets `_ck_loaded = True` as a graceful fallback when `ck_prices_cache.json` is missing at startup, preventing it from reloading the file if it is later written to disk. Added `invalidate_ck_cache()` to `PriceService`; the `Download from GitHub` route and the orchestrator auto-download now call it after successfully downloading `ck_prices_cache.json`, so CK prices appear immediately without a container restart.
|
||||||
|
|
||||||
## [4.6.2] - 2026-04-04
|
## [4.6.2] - 2026-04-04
|
||||||
### Fixed
|
### Fixed
|
||||||
- **CK prices missing after GitHub cache download**: `ck_prices_cache.json` was not included in the files committed to `similarity-cache-data` by the build workflow, nor fetched by the `Download from GitHub` button or the orchestrator auto-download flow. All three paths now include the file (graceful 404 handling preserves backward compatibility with existing cache branches).
|
- **CK prices missing after GitHub cache download**: `ck_prices_cache.json` was not included in the files committed to `similarity-cache-data` by the build workflow, nor fetched by the `Download from GitHub` button or the orchestrator auto-download flow. All three paths now include the file (graceful 404 handling preserves backward compatibility with existing cache branches).
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,14 @@ async def download_github():
|
||||||
msg = f"Downloaded {len(downloaded)} file(s) from GitHub"
|
msg = f"Downloaded {len(downloaded)} file(s) from GitHub"
|
||||||
if failed:
|
if failed:
|
||||||
msg += f" ({len(failed)} unavailable)"
|
msg += f" ({len(failed)} unavailable)"
|
||||||
|
# Invalidate in-memory CK price cache if the file was downloaded
|
||||||
|
# so the singleton reloads it without a container restart.
|
||||||
|
if any("ck_prices_cache.json" in f for f in downloaded):
|
||||||
|
try:
|
||||||
|
from code.web.services.price_service import get_price_service
|
||||||
|
get_price_service().invalidate_ck_cache()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
return JSONResponse({
|
return JSONResponse({
|
||||||
"ok": True,
|
"ok": True,
|
||||||
"message": msg,
|
"message": msg,
|
||||||
|
|
|
||||||
|
|
@ -1408,6 +1408,13 @@ def _ensure_setup_ready(out, force: bool = False) -> None:
|
||||||
"percent": 100,
|
"percent": 100,
|
||||||
"finished_at": _dt.now().isoformat(timespec='seconds')
|
"finished_at": _dt.now().isoformat(timespec='seconds')
|
||||||
})
|
})
|
||||||
|
# Invalidate in-memory CK price cache so the singleton picks up
|
||||||
|
# the newly downloaded ck_prices_cache.json without a restart.
|
||||||
|
try:
|
||||||
|
from code.web.services.price_service import get_price_service
|
||||||
|
get_price_service().invalidate_ck_cache()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
# Refresh theme catalog after successful download
|
# Refresh theme catalog after successful download
|
||||||
_refresh_theme_catalog(out, force=False, fast_path=True)
|
_refresh_theme_catalog(out, force=False, fast_path=True)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -546,6 +546,18 @@ class PriceService(BaseService):
|
||||||
# rather than blocking every request. CK rebuild happens via Setup page.
|
# rather than blocking every request. CK rebuild happens via Setup page.
|
||||||
self._ck_loaded = True
|
self._ck_loaded = True
|
||||||
|
|
||||||
|
def invalidate_ck_cache(self) -> None:
|
||||||
|
"""Reset the CK loaded flag so the cache is re-read from disk on next access.
|
||||||
|
|
||||||
|
Call this after externally writing a new ck_prices_cache.json (e.g. after
|
||||||
|
downloading a pre-built cache from GitHub) so the in-memory singleton
|
||||||
|
picks up the new file without a container restart.
|
||||||
|
"""
|
||||||
|
with self._lock:
|
||||||
|
self._ck_loaded = False
|
||||||
|
self._ck_cache = {}
|
||||||
|
logger.info("CK price cache invalidated — will reload on next access.")
|
||||||
|
|
||||||
def _rebuild_ck_cache(self) -> None:
|
def _rebuild_ck_cache(self) -> None:
|
||||||
"""Fetch the Card Kingdom price list and cache retail prices by card name.
|
"""Fetch the Card Kingdom price list and cache retail prices by card name.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ services:
|
||||||
# WEB_THEME_FILTER_PREWARM: "0"
|
# WEB_THEME_FILTER_PREWARM: "0"
|
||||||
WEB_AUTO_ENFORCE: "0" # 1=auto-run compliance export after builds
|
WEB_AUTO_ENFORCE: "0" # 1=auto-run compliance export after builds
|
||||||
WEB_CUSTOM_EXPORT_BASE: "" # Optional: custom base dir for deck export artifacts
|
WEB_CUSTOM_EXPORT_BASE: "" # Optional: custom base dir for deck export artifacts
|
||||||
APP_VERSION: "v4.6.2" # Displayed version label (set per release/tag)
|
APP_VERSION: "v4.6.3" # Displayed version label (set per release/tag)
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Misc / Land Selection (Step 7) Environment Tuning
|
# Misc / Land Selection (Step 7) Environment Tuning
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ services:
|
||||||
# WEB_THEME_FILTER_PREWARM: "0"
|
# WEB_THEME_FILTER_PREWARM: "0"
|
||||||
WEB_AUTO_ENFORCE: "0" # 1=auto-run compliance export after builds
|
WEB_AUTO_ENFORCE: "0" # 1=auto-run compliance export after builds
|
||||||
WEB_CUSTOM_EXPORT_BASE: "" # Optional: custom base dir for deck export artifacts
|
WEB_CUSTOM_EXPORT_BASE: "" # Optional: custom base dir for deck export artifacts
|
||||||
APP_VERSION: "v4.6.2" # Displayed version label (set per release/tag)
|
APP_VERSION: "v4.6.3" # Displayed version label (set per release/tag)
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Misc / Land Selection (Step 7) Environment Tuning
|
# Misc / Land Selection (Step 7) Environment Tuning
|
||||||
|
|
|
||||||
4
docs/releases/v4.6.3.md
Normal file
4
docs/releases/v4.6.3.md
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
# MTG Python Deckbuilder v4.6.3
|
||||||
|
|
||||||
|
## Fixed
|
||||||
|
- **CK prices not loading after GitHub cache download**: The `PriceService` singleton marks `_ck_loaded = True` as a graceful fallback when `ck_prices_cache.json` is absent at startup. If the file was then downloaded during a running container (via "Download from GitHub" or the orchestrator auto-download), the in-memory flag prevented it from ever being read. `PriceService.invalidate_ck_cache()` is now called after a successful download, forcing a reload on the next price request without requiring a container restart.
|
||||||
|
|
@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "mtg-deckbuilder"
|
name = "mtg-deckbuilder"
|
||||||
version = "4.6.2"
|
version = "4.6.3"
|
||||||
description = "A command-line tool for building and analyzing Magic: The Gathering decks"
|
description = "A command-line tool for building and analyzing Magic: The Gathering decks"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = {file = "LICENSE"}
|
license = {file = "LICENSE"}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue