fix: invalidate stale 12-item volume rank cache and force full top20 refresh
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -26,6 +26,7 @@ from hub_ohlcv_lib import (
|
||||
)
|
||||
from hub_volume_rank_lib import (
|
||||
TOP_N_DEFAULT,
|
||||
_exchange_rank_row_stale,
|
||||
cache_needs_refresh,
|
||||
format_volume_quote,
|
||||
get_cached_rank,
|
||||
@@ -343,7 +344,7 @@ def _fetch_instance_volume_rank_sync(ex: dict, *, top_n: int = TOP_N_DEFAULT) ->
|
||||
params = {"top": str(int(top_n))}
|
||||
url = f"{base}/api/hub/volume-rank?{urlencode(params)}"
|
||||
try:
|
||||
with httpx.Client(timeout=max(HUB_FLASK_TIMEOUT, 60.0)) as client:
|
||||
with httpx.Client(timeout=max(HUB_FLASK_TIMEOUT, 120.0)) as client:
|
||||
r = client.get(url, headers=_hub_headers())
|
||||
if r.status_code >= 400:
|
||||
parsed = _parse_http_json_body(r)
|
||||
@@ -367,14 +368,21 @@ def _refresh_volume_ranks(*, force: bool = False) -> dict:
|
||||
global _volume_rank_cache
|
||||
expected = rank_date_label()
|
||||
cache = _get_volume_rank_cache()
|
||||
if not force and not cache_needs_refresh(cache, expected_rank_date=expected):
|
||||
targets = enabled_exchanges(load_settings())
|
||||
required_keys = [
|
||||
str(ex.get("key") or "").strip().lower()
|
||||
for ex in targets
|
||||
if ex.get("enabled") and str(ex.get("key") or "").strip()
|
||||
]
|
||||
if not force and not cache_needs_refresh(
|
||||
cache, expected_rank_date=expected, required_keys=required_keys
|
||||
):
|
||||
return {
|
||||
"ok": True,
|
||||
"skipped": True,
|
||||
"rank_date": cache.get("rank_date"),
|
||||
"updated_at": cache.get("updated_at"),
|
||||
}
|
||||
targets = enabled_exchanges(load_settings())
|
||||
errors: list[str] = []
|
||||
for ex in targets:
|
||||
ex_key = str(ex.get("key") or "").strip().lower()
|
||||
@@ -782,10 +790,22 @@ def api_chart_volume_rank(exchange_key: str = "", refresh: str = ""):
|
||||
if not result.get("ok"):
|
||||
raise HTTPException(status_code=502, detail=result.get("msg") or "刷新失败")
|
||||
cache = _get_volume_rank_cache()
|
||||
if cache_needs_refresh(cache):
|
||||
_refresh_volume_ranks(force=False)
|
||||
cache = _get_volume_rank_cache()
|
||||
ex_k = (exchange_key or "").strip().lower()
|
||||
targets = enabled_exchanges(load_settings())
|
||||
required_keys = [
|
||||
str(ex.get("key") or "").strip().lower()
|
||||
for ex in targets
|
||||
if ex.get("enabled") and str(ex.get("key") or "").strip()
|
||||
]
|
||||
need_keys = [ex_k] if ex_k else required_keys
|
||||
if cache_needs_refresh(cache, required_keys=need_keys):
|
||||
_refresh_volume_ranks(force=True)
|
||||
cache = _get_volume_rank_cache()
|
||||
elif ex_k:
|
||||
row = (cache.get("exchanges") or {}).get(ex_k) or {}
|
||||
if _exchange_rank_row_stale(row):
|
||||
_refresh_volume_ranks(force=True)
|
||||
cache = _get_volume_rank_cache()
|
||||
if ex_k:
|
||||
ex = _find_exchange_by_key(ex_k)
|
||||
if not ex:
|
||||
|
||||
Reference in New Issue
Block a user