perf(image): 图库清单去 base64(367KB→1.6KB,按 thumbHash 读文件)+ 画布显示缩略图 768px 落盘
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m36s

This commit is contained in:
qiqi committed 2026-11-17 15:36:20 +08:00
1 parent e9a6402373
commit 3bbf1ea85d
3 files changed
+140 -5

No files matched your search

+46 -1
View File
@@ -1654,7 +1654,7 @@
const RuntimeConstants = (typeof window !== 'undefined' && window.IWBRuntimeConstants) || { outputLimit: 10000, galleryRanges: {} }
const GalleryHydration = typeof window !== 'undefined' && window.IWBGalleryHydration
const galleryHydrator = GalleryHydration && typeof GalleryHydration.create === 'function'
? GalleryHydration.create({ get: (key) => IDB.get(key) })
? GalleryHydration.create({ get: (key) => IDB.get(key), thumb: (hash) => { const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null; return (F && typeof F.galleryThumb === 'function') ? F.galleryThumb(hash) : Promise.resolve('') } })
: null
const ModularOutputStore = typeof window !== 'undefined' && window.IWBStorageOutputs && ModularLocalStore && ModularIndexedStore
? window.IWBStorageOutputs.create({ local: ModularLocalStore, indexedDb: ModularIndexedStore, key: OUT_KEY, prefix: 'out_', limit: RuntimeConstants.outputLimit, hydrate: galleryHydrator && ((items) => galleryHydrator.hydrate(items)) })
@@ -4643,6 +4643,48 @@ const tbCenterSeed = (type, refs) => {
previewUrls.clear(); previewPending.clear()
}
// 显示缩略图落盘(768px):下次启动直接读文件,不用再解码原图
const DISPLAY_THUMB_HASH_MAX = 512
const displayThumbSaved = new Set()
function wStoreMod () {
const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null
return (F && typeof F.readDisplayThumb === 'function') ? F : null
}
function wSaveDisplayThumb (key, dataUrl) {
const F = wStoreMod()
if (!F || !key || !dataUrl) return
if (displayThumbSaved.has(key) || displayThumbSaved.size > 2000) return
displayThumbSaved.add(key)
wSha256(String(key)).then(function (hex) {
try { F.writeDisplayThumb(hex.slice(0, 16), dataUrl) } catch (e) { /* ignore */ }
}).catch(function () { /* ignore */ })
}
async function wPreloadDisplayThumbs (nodes) {
const F = wStoreMod()
if (!F || !Array.isArray(nodes) || !nodes.length) return 0
const keys = []
for (const n of nodes) {
const d = n && n.data
if (!d) continue
const v = wResolveImg(d.data) || d.url
if (!v || typeof v !== 'string' || v.indexOf('data:') === 0) continue
const key = wDisplayThumbKey(v)
if (!key || displayThumbs.has(key) || keys.indexOf(key) >= 0) continue
keys.push(key)
if (keys.length >= DISPLAY_THUMB_HASH_MAX) break
}
let n = 0
for (const key of keys) {
try {
const hex = await wSha256(String(key))
const dataUrl = await F.readDisplayThumb(hex.slice(0, 16))
if (dataUrl) { displayThumbs.set(key, dataUrl); displayThumbSaved.add(key); n++ }
} catch (e) { /* 单张失败忽略 */ }
}
if (n && typeof wThumbBump === 'function') { try { wThumbBump() } catch (e) { /* ignore */ } }
return n
}
function wDisplayThumbOf(v) {
// C3:结果项 / 图片节点的 data 可能是引用对象(hydrate 直出)→ 先解析成显示 URL
if (v && typeof v === 'object') v = wResolveImg(v)
@@ -4679,6 +4721,7 @@ const tbCenterSeed = (type, refs) => {
const small = cv.toDataURL('image/jpeg', 0.78)
if (displayThumbs.size >= DISPLAY_THUMB_CACHE_MAX) { const first = displayThumbs.keys().next().value; if (first !== undefined) displayThumbs.delete(first) }
wRememberThumb(small)
try { wSaveDisplayThumb(key, small) } catch (e) { /* ignore */ }
displayThumbPending.delete(key)
if (typeof wThumbBump === 'function') { try { wThumbBump() } catch (e) { /* ignore */ } }
} catch (e) { displayThumbPending.delete(key); wRememberThumb(v) } // 失败也记下:不再每次渲染重复解码整图
@@ -6173,6 +6216,8 @@ const tbCenterSeed = (type, refs) => {
refs.syncing = true // 切换/同步载入不触发自动保存(避免轮询-保存死循环)
setSel([]); setSelEdge(null)
openSession(id) // S3:先激活 session,再从它加载历史(session 化)
// 显示缩略图预热(768px 文件已存在就直接命中,省掉一次 4K 解码)
try { setTimeout(function () { wPreloadDisplayThumbs(ns).catch(function () { /* ignore */ }) }, 0) } catch (e) { /* ignore */ }
const sess = sessionsStore.get(id)
if (sess) { sess.nodes = ns; sess.edges = es; sess.groups = gs; sess.dirty = false } // S6:装载即同步 session 并清脏(装载不算本地编辑)
refs.history = (sess && sess.history) ? sess.history : { stack: [], idx: -1 } // S3:历史随 session(不再全局清空)