Revert "fix(options): speed up chain refresh with fast path and non-blocking UI"

This reverts commit 6fad68f7b1.
This commit is contained in:
dekun
2026-08-11 12:22:41 +08:00
parent 6fad68f7b1
commit a488e2fabd
5 changed files with 19 additions and 153 deletions
+12 -32
View File
@@ -1450,14 +1450,8 @@
const uly = state.underlying;
const seq = ++chainLoadSeq;
const btn = document.getElementById("opt-load-chain");
const hadChain = chainHasExpiries(state.chain) && state.chain.underlying === uly;
if (btn && !soft) {
btn.disabled = true;
if (!btn.dataset.origText) btn.dataset.origText = btn.textContent || "刷新链";
btn.textContent = "刷新中…";
}
// 已有链时不先清空表格,避免「白屏等很久」的体感
if (!soft && !hadChain) {
if (btn && !soft) btn.disabled = true;
if (!soft) {
setExpirySelectStatus("加载到期日中…");
const tbody = document.getElementById("opt-strike-tbody");
if (tbody) {
@@ -1468,18 +1462,9 @@
try {
let d = null;
let lastMsg = "";
const expMs = (document.getElementById("opt-exp-select") || {}).value || "";
// WS 已热时走 fast,跳过最慢的整家族 REST tickers
const useFast = soft || quoteLiveWsOk || hadChain;
const maxAttempts = soft ? 2 : 3;
for (let attempt = 0; attempt < maxAttempts; attempt++) {
for (let attempt = 0; attempt < 3; attempt++) {
if (seq !== chainLoadSeq) return;
let url =
"/api/options/chain?underlying=" +
encodeURIComponent(uly) +
(useFast ? "&fast=1" : "");
if (expMs) url += "&exp_time=" + encodeURIComponent(expMs);
d = await apiJson(url);
d = await apiJson("/api/options/chain?underlying=" + encodeURIComponent(uly));
if (seq !== chainLoadSeq) return;
if (d && d.ok && chainHasExpiries(d)) break;
lastMsg = (d && (d.msg || d.chain_error)) || "暂无到期日";
@@ -1487,14 +1472,14 @@
!!(d && d.rate_limited) ||
/50011|Too Many Requests|过于频繁/i.test(String(lastMsg || ""));
d = null;
if (attempt < maxAttempts - 1) {
if (!soft && !hadChain) {
if (attempt < 2) {
if (!soft) {
setExpirySelectStatus(
rateLimited ? "OKX 限频,稍后重试…" : "重试加载到期日…"
);
}
await new Promise(function (resolve) {
setTimeout(resolve, rateLimited ? 1200 * (attempt + 1) : 300);
setTimeout(resolve, rateLimited ? 1200 * (attempt + 1) : 400);
});
}
}
@@ -1504,7 +1489,6 @@
if (!soft) {
renderExpiries();
renderStrikes();
void watchCurrentExpiryQuotes();
}
return;
}
@@ -1526,7 +1510,7 @@
alert(friendly);
return;
}
const keepExp = soft || hadChain ? (document.getElementById("opt-exp-select") || {}).value : "";
const keepExp = soft ? (document.getElementById("opt-exp-select") || {}).value : "";
state.chain = d;
panelCache.chain = d;
panelCache.underlying = uly;
@@ -1534,7 +1518,7 @@
chainQuotedAt = Date.now();
lastChainSoftAt = chainQuotedAt;
syncAskLiqFilterFromChain(d);
if (!soft && !hadChain) {
if (!soft) {
state.selectedInst = null;
resetMoneyFilterToAll();
state.strikeExpandAll = false;
@@ -1544,19 +1528,18 @@
}
updateUnderlyingLabel();
renderExpiries();
if (keepExp) {
if (soft && keepExp) {
const sel = document.getElementById("opt-exp-select");
if (sel && Array.from(sel.options).some(function (o) { return o.value === keepExp; })) {
sel.value = keepExp;
}
}
// soft/已有链时保留 selectedInstrenderStrikes 会先 park 再按 prevSelected 静默重挂下单面板
// soft 时保留 selectedInstrenderStrikes 会先 park 再按 prevSelected 静默重挂下单面板
renderStrikes();
void watchCurrentExpiryQuotes();
startQuoteLiveStream();
} catch (e) {
if (seq !== chainLoadSeq || soft) return;
if (hadChain) return;
setExpirySelectStatus("选择到期日");
const tbody = document.getElementById("opt-strike-tbody");
if (tbody) {
@@ -1566,10 +1549,7 @@
"</td></tr>";
}
} finally {
if (seq === chainLoadSeq && btn) {
btn.disabled = false;
if (btn.dataset.origText) btn.textContent = btn.dataset.origText;
}
if (seq === chainLoadSeq && btn) btn.disabled = false;
}
}