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:
@@ -2629,15 +2629,24 @@
|
||||
const rankDate = data.rank_date || "—";
|
||||
const updated = data.updated_at || "—";
|
||||
const total = data.total_symbols != null ? data.total_symbols : "";
|
||||
elVolRankMeta.textContent =
|
||||
"昨日成交 Top20 · 交易日 " +
|
||||
const count = data.items.length;
|
||||
const expect = data.expected_count != null ? data.expected_count : 20;
|
||||
let meta =
|
||||
"昨日成交 Top" +
|
||||
expect +
|
||||
" · 交易日 " +
|
||||
rankDate +
|
||||
" · 每早 " +
|
||||
resetHour +
|
||||
":00 更新" +
|
||||
(total ? " · 全市场 " + total + " 个" : "") +
|
||||
" · " +
|
||||
updated;
|
||||
":00 更新 · 显示 " +
|
||||
count +
|
||||
"/" +
|
||||
expect +
|
||||
" 条";
|
||||
if (total) meta += " · 全市场 " + total + " 个";
|
||||
if (data.stale) meta += " · 数据不完整,正在重拉…";
|
||||
meta += " · " + updated;
|
||||
elVolRankMeta.textContent = meta;
|
||||
const curSym = (elSymbol && elSymbol.value.trim().toUpperCase()) || "";
|
||||
data.items.forEach(function (row) {
|
||||
const li = document.createElement("li");
|
||||
@@ -2667,21 +2676,24 @@
|
||||
});
|
||||
}
|
||||
|
||||
async function loadVolumeRank() {
|
||||
async function loadVolumeRank(forceRefresh) {
|
||||
const exKey = (elExchange && elExchange.value) || "";
|
||||
if (!exKey || !elVolRankMeta) return;
|
||||
elVolRankMeta.textContent = "加载排名…";
|
||||
if (elVolRankList) elVolRankList.innerHTML = "";
|
||||
try {
|
||||
const r = await fetch(
|
||||
"/api/chart/volume-rank?exchange_key=" + encodeURIComponent(exKey),
|
||||
{ credentials: "same-origin" }
|
||||
);
|
||||
let url = "/api/chart/volume-rank?exchange_key=" + encodeURIComponent(exKey);
|
||||
if (forceRefresh) url += "&refresh=1";
|
||||
const r = await fetch(url, { credentials: "same-origin" });
|
||||
const data = await r.json();
|
||||
if (!r.ok) {
|
||||
throw new Error((data && data.detail) || (data && data.msg) || "加载失败");
|
||||
}
|
||||
renderVolumeRank(data);
|
||||
const expect = data.expected_count != null ? data.expected_count : 20;
|
||||
if (!forceRefresh && data.ok && data.items && data.items.length < expect) {
|
||||
void loadVolumeRank(true);
|
||||
}
|
||||
} catch (e) {
|
||||
renderVolumeRank({ ok: false, msg: String(e.message || e) });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user