fix: isolate overlapping Human Gate loads
This commit is contained in:
1 parent
9d84d5c5c4
commit
ab329aa126
2 files changed
+16
No files matched your search
@@ -10,6 +10,7 @@ function createHumanGates(options = {}) {
|
||||
let reviewSnapshot = [];
|
||||
let reviewIndex = -1;
|
||||
let loadedAccountKey = '';
|
||||
let loadEpoch = 0;
|
||||
const decisionKeys = new Map();
|
||||
let decisionFlight = null;
|
||||
|
||||
@@ -80,6 +81,7 @@ function createHumanGates(options = {}) {
|
||||
}
|
||||
|
||||
async function load() {
|
||||
const epoch = ++loadEpoch;
|
||||
const accountKey = String(getAccountKey() || '').trim().toLowerCase();
|
||||
if (accountKey !== loadedAccountKey) {
|
||||
loadedAccountKey = accountKey;
|
||||
@@ -92,12 +94,14 @@ function createHumanGates(options = {}) {
|
||||
if (cached) { queue = cached; render(); }
|
||||
try {
|
||||
const live = validSnapshot(await fetchJson('api/v1/human-gates'));
|
||||
if (epoch !== loadEpoch || accountKey !== loadedAccountKey) return queue;
|
||||
if (!live) throw new Error('Human Gates response is invalid.');
|
||||
queue = { pending_count: live.pending_count, items: live.items.slice() };
|
||||
save(queue);
|
||||
render();
|
||||
return queue;
|
||||
} catch (error) {
|
||||
if (epoch !== loadEpoch || accountKey !== loadedAccountKey) return queue;
|
||||
if (!cached) throw error;
|
||||
setText(nodes.status, 'Offline cached gate list · reconnect before deciding.');
|
||||
return queue;
|
||||
|
||||
Reference in new issue
Block a user