perf(gallery): v3.26.131 缩略图改 objectURL(修宫格加载慢)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 39s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 39s
This commit is contained in:
1 parent
3e0fb3bdf8
commit
e59011b591
8 files changed
+51
-7
No files matched your search
+5
-1
@@ -186,7 +186,7 @@
|
||||
// 等缩略图就绪(最多 ~3s):宫格显示「加载中…」好过把 8MB base64 塞进 DOM
|
||||
const settle = async (src) => {
|
||||
if (!src) return ''
|
||||
for (let i = 0; i < 15; i++) {
|
||||
for (let i = 0; i < 8; i++) { // v3.26.131:3s → 1.6s,缺缩略图的卡别把宫格拖住
|
||||
const u = display(src)
|
||||
if (u && !HUGE_DATA(u)) return u
|
||||
await new Promise((r) => setTimeout(r, 200))
|
||||
@@ -198,6 +198,10 @@
|
||||
// 原因:displayThumbOf 会给每张图 mint 一个 objectURL 并写进宿主 displayThumbs(300),
|
||||
// 点开图库面板就是上百个 objectURL + 上百张 512 解码位图;关闭面板后这些 URL 仍被缓存持有,
|
||||
// 位图也就跟着留着。320 缩略图本身是 ~20KB 的 data URL,内核可随时丢弃,直接给 <img> 最省。
|
||||
// v3.26.131:优先要 **objectURL**(首帧可用、重复打开零成本);拿不到再退回 dataURL。
|
||||
if (f.thumbHash && typeof e.galleryThumbUrl === 'function') {
|
||||
try { const v = await e.galleryThumbUrl(f.thumbHash); if (v) return v } catch (err) { /* 继续 */ }
|
||||
}
|
||||
if (f.thumbHash && typeof e.galleryThumb === 'function') {
|
||||
try { const v = await e.galleryThumb(f.thumbHash); if (v && !HUGE_DATA(v)) return v } catch (err) { /* 继续本地副本 */ }
|
||||
}
|
||||
|
||||
+32
-1
@@ -1071,6 +1071,37 @@
|
||||
thumbMapCache = map
|
||||
return map
|
||||
}
|
||||
// v3.26.131:宫格缩略图改发 **objectURL**(同一张只读一次盘、只建一次 URL)。
|
||||
// 原来每张都 base64 成 dataURL(20~40KB 字符串),164 张 ⇒ 每次开面板 3~6MB 字符串 + 164 次 IPC,
|
||||
// 这就是「能加载但很慢」的来源。objectURL 首帧即用,重复打开直接命中。
|
||||
const galleryUrlCache = new Map()
|
||||
async function galleryThumbUrl(hash) {
|
||||
try {
|
||||
if (!enabled() || !dir || !hash) return ''
|
||||
const k = String(hash)
|
||||
const hit = galleryUrlCache.get(k)
|
||||
if (hit) {
|
||||
// 命中移到队尾(LRU)
|
||||
galleryUrlCache.delete(k); galleryUrlCache.set(k, hit)
|
||||
return hit
|
||||
}
|
||||
const map = await thumbFileMap()
|
||||
const name = map[k]
|
||||
if (!name) return ''
|
||||
const u8 = await fs().readFile(await join(dir, IMG_DIR, 'thumbs', name))
|
||||
if (!u8 || !u8.length) return ''
|
||||
const mime = sniffMime(u8) || (/\.png$/i.test(name) ? 'image/png' : 'image/jpeg')
|
||||
const url = URL.createObjectURL(new Blob([u8], { type: mime }))
|
||||
galleryUrlCache.set(k, url)
|
||||
while (galleryUrlCache.size > 500) {
|
||||
const oldK = galleryUrlCache.keys().next().value
|
||||
try { URL.revokeObjectURL(galleryUrlCache.get(oldK)) } catch (e) { /* ignore */ }
|
||||
galleryUrlCache.delete(oldK)
|
||||
}
|
||||
return url
|
||||
} catch (e) { return '' }
|
||||
}
|
||||
|
||||
async function galleryThumb(hash) {
|
||||
try {
|
||||
if (!enabled() || !dir || !hash) return ''
|
||||
@@ -1533,7 +1564,7 @@
|
||||
enabled, ready: init, flush,
|
||||
// 供其它模块把诊断写进 _boot.log(v3.26.109)
|
||||
logLine: (m) => blog(m),
|
||||
runtime, pickDir, switchTo, migrateTo, deleteImageBytes, deleteGalleryBytesFor, galleryAudit, gcImages, rotateTrash, galleryThumb, readDisplayThumb, readDisplayThumbUrl, makeDisplayThumb, makeDisplayThumbFromPath, resizeDataUrl, decodeStats, thumbStats, writeDisplayThumb, writeDisplayThumbBlob, pruneThumbs, cleanupLegacy, maintain,
|
||||
runtime, pickDir, switchTo, migrateTo, deleteImageBytes, deleteGalleryBytesFor, galleryAudit, gcImages, rotateTrash, galleryThumb, galleryThumbUrl, readDisplayThumb, readDisplayThumbUrl, makeDisplayThumb, makeDisplayThumbFromPath, resizeDataUrl, decodeStats, thumbStats, writeDisplayThumb, writeDisplayThumbBlob, pruneThumbs, cleanupLegacy, maintain,
|
||||
plugins: { manifest: pluginManifest, read: pluginRead, write: pluginWrite, remove: pluginRemove, dir: pluginDir, listLocal: pluginListLocal, listDirs: pluginListDirs, readFile: pluginReadFile, writeFile: pluginWriteFile, writeBinary: pluginWriteBinary, mkdir: pluginMkdir, removeDir: pluginRemoveDir, renameDir: pluginRenameDir, existsDir: pluginExistsDir },
|
||||
pluginData: { read: pluginDataRead, write: pluginDataWrite, remove: pluginDataRemove, list: pluginDataList },
|
||||
pluginFiles: { put: pluginFilePut, get: pluginFileGet, list: pluginFileList, remove: pluginFileRemove, stat: pluginFileStat, dir: pluginFilesDir, readBytes: pluginFileReadBytes, listAll: pluginFilesListAll },
|
||||
|
||||
Reference in new issue
Block a user