Fix dashboard mobile load issues and simplify card layout.
Reduce poll pressure on phone/tablet, cache key prices, and handle live API errors gracefully. Rework mobile position and close cards with inline direction, compact P/L line, and detail modal. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+20
-1
@@ -10,6 +10,25 @@ from typing import Any, Callable, Optional
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
_TZ = ZoneInfo("Asia/Shanghai")
|
||||
_PRICE_CACHE: dict[str, tuple[float, float]] = {}
|
||||
_PRICE_CACHE_TTL = 2.0
|
||||
|
||||
|
||||
def _cached_fetch_price(
|
||||
fetch_price: Callable[[str, str, str], Optional[float]],
|
||||
sym: str,
|
||||
market: str,
|
||||
sina: str,
|
||||
) -> Optional[float]:
|
||||
key = sym or ""
|
||||
now = datetime.now().timestamp()
|
||||
hit = _PRICE_CACHE.get(key)
|
||||
if hit and (now - hit[1]) < _PRICE_CACHE_TTL:
|
||||
return hit[0]
|
||||
price = fetch_price(sym, market, sina)
|
||||
if price is not None:
|
||||
_PRICE_CACHE[key] = (float(price), now)
|
||||
return price
|
||||
|
||||
|
||||
def _direction_label(direction: str) -> str:
|
||||
@@ -174,7 +193,7 @@ def build_dashboard_payload(
|
||||
sina = r["sina_code"] or ""
|
||||
upper = float(r["upper"] or 0)
|
||||
lower = float(r["lower"] or 0)
|
||||
price = fetch_price(sym, market, sina)
|
||||
price = _cached_fetch_price(fetch_price, sym, market, sina)
|
||||
dist_upper = dist_lower = None
|
||||
if price is not None:
|
||||
dist_upper = round(upper - float(price), 2)
|
||||
|
||||
Reference in New Issue
Block a user