修复板块切换数据合并:禁止 API 响应缓存(反代按 path 忽略 query 导致两个 tab 数据相同)
This commit is contained in:
@@ -1,10 +1,15 @@
|
|||||||
"""板块数据路由:行业板块、概念板块"""
|
"""板块数据路由:行业板块、概念板块"""
|
||||||
|
|
||||||
from fastapi import APIRouter, Query, HTTPException
|
from fastapi import APIRouter, Query, HTTPException
|
||||||
|
from fastapi.responses import JSONResponse
|
||||||
from services import eastmoney, mootdx
|
from services import eastmoney, mootdx
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
# 行业/概念通过 query 参数区分,但上游反代/CDN 可能按 path 缓存而忽略 query,
|
||||||
|
# 导致两个 tab 返回相同数据。显式禁止缓存,保证按 query 区分。
|
||||||
|
_NO_CACHE_HEADERS = {"Cache-Control": "no-store, no-cache, must-revalidate, max-age=0"}
|
||||||
|
|
||||||
|
|
||||||
@router.get("", summary="板块列表")
|
@router.get("", summary="板块列表")
|
||||||
async def sector_list(
|
async def sector_list(
|
||||||
@@ -15,11 +20,20 @@ async def sector_list(
|
|||||||
|
|
||||||
data = await eastmoney.fetch_sector_list(type)
|
data = await eastmoney.fetch_sector_list(type)
|
||||||
if data:
|
if data:
|
||||||
return {"data": data, "count": len(data), "type": type}
|
return JSONResponse(
|
||||||
|
{"data": data, "count": len(data), "type": type},
|
||||||
|
headers=_NO_CACHE_HEADERS,
|
||||||
|
)
|
||||||
|
|
||||||
# 降级:通达信 mootdx(不含实时资金流数据)
|
# 降级:通达信 mootdx(不含实时资金流数据)
|
||||||
md_data = await mootdx.fetch_sector_list(type)
|
md_data = await mootdx.fetch_sector_list(type)
|
||||||
if md_data:
|
if md_data:
|
||||||
return {"data": md_data, "count": len(md_data), "type": type, "source": "mootdx"}
|
return JSONResponse(
|
||||||
|
{"data": md_data, "count": len(md_data), "type": type, "source": "mootdx"},
|
||||||
|
headers=_NO_CACHE_HEADERS,
|
||||||
|
)
|
||||||
|
|
||||||
return {"data": [], "count": 0, "type": type}
|
return JSONResponse(
|
||||||
|
{"data": [], "count": 0, "type": type},
|
||||||
|
headers=_NO_CACHE_HEADERS,
|
||||||
|
)
|
||||||
|
|||||||
@@ -468,7 +468,7 @@ export async function fetchSectors(type: SectorType, signal?: AbortSignal): Prom
|
|||||||
const url = `${baseUrl}/api/sectors?type=${type}`;
|
const url = `${baseUrl}/api/sectors?type=${type}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(url, { method: "GET", signal });
|
const resp = await fetch(url, { method: "GET", signal, cache: "no-store" });
|
||||||
if (!resp.ok) return [];
|
if (!resp.ok) return [];
|
||||||
const result: SectorResponse = await resp.json();
|
const result: SectorResponse = await resp.json();
|
||||||
return result.data || [];
|
return result.data || [];
|
||||||
|
|||||||
Reference in New Issue
Block a user