perf: 缩略图失败 key 负缓存(v3.26.181 实际源码,之前漏提交)
Verify (Gitea) / gate (build · unit · facts) (push) Canceled after 13m54s

This commit is contained in:
qiqi committed 2026-12-01 21:48:16 +08:00
1 parent 7d0ee9c11a
commit f0b75b401d
1 file changed
+6 -3
+6 -3
View File
@@ -25,6 +25,9 @@
const pending = o.pending
if (!cache || !pending) throw new Error('cache/pending required')
const queue = []
// v3.26.181:失败过的 key 不再重试(标注覆盖后的新图没有缩略图,生成失败时
// 每次重渲染都会重新入队 → 反复整幅解码,CPU 被吃掉)。
const failed = new Set()
let running = 0
let scheduled = false
@@ -146,7 +149,7 @@
try { ok = await runNative(key) } catch (e) { ok = false }
if (!ok) { try { ok = await runBitmap(key, v) } catch (e) { ok = false } }
if (!ok) { try { ok = await runImg(key, v) } catch (e2) { ok = false } }
if (ok) bump()
if (ok) { failed.delete(key); bump() } else if (!(typeof o.isTransient === 'function' && o.isTransient(v))) failed.add(key)
return ok
}
@@ -174,13 +177,13 @@
return {
queue: function (key, v) {
if (!key || cache.has(key) || pending.has(key)) return false
if (!key || cache.has(key) || pending.has(key) || failed.has(key)) return false
pending.add(key)
queue.push({ key: key, v: v })
schedule()
return true
},
stats: function () { return { queued: queue.length, running: running } }
stats: function () { return { queued: queue.length, running: running, failed: failed.size } }
}
}