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:
dekun
2026-06-08 16:01:27 +08:00
parent 89a58c7323
commit 93b84da72e
5 changed files with 94 additions and 24 deletions
+10
View File
@@ -2,6 +2,8 @@ from datetime import datetime
from hub_volume_rank_lib import (
CACHE_VERSION,
TOP_N_DEFAULT,
_exchange_rank_row_stale,
_okx_turnover_usdt,
cache_needs_refresh,
format_volume_quote,
@@ -53,3 +55,11 @@ def test_cache_needs_refresh_and_merge():
def test_stale_cache_version_forces_refresh():
cache = {"version": CACHE_VERSION - 1, "rank_date": "2026-06-07", "exchanges": {"okx": {"items": [{}]}}}
assert cache_needs_refresh(cache) is True
def test_short_item_list_is_stale():
items = [{"rank": i, "symbol": f"S{i}/USDT"} for i in range(1, 13)]
row = {"items": items, "total_symbols": 12}
assert _exchange_rank_row_stale(row) is True
full = {"items": items + [{"rank": i, "symbol": f"X{i}/USDT"} for i in range(13, TOP_N_DEFAULT + 1)], "total_symbols": 300}
assert _exchange_rank_row_stale(full) is False