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
+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