From e59011b591fdffeed5722b0f80d2862426e371ec Mon Sep 17 00:00:00 2001 From: qiqi Date: Mon, 30 Nov 2026 18:37:25 +0800 Subject: [PATCH] =?UTF-8?q?perf(gallery):=20v3.26.131=20=E7=BC=A9=E7=95=A5?= =?UTF-8?q?=E5=9B=BE=E6=94=B9=20objectURL=EF=BC=88=E4=BF=AE=E5=AE=AB?= =?UTF-8?q?=E6=A0=BC=E5=8A=A0=E8=BD=BD=E6=85=A2=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 9 +++++++++ app.js | 2 +- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 2 +- src/gallery-sync.js | 6 +++++- src/storage-file.js | 33 ++++++++++++++++++++++++++++++++- 8 files changed, 51 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc295b2..7328db4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,15 @@ > 3. 核验正式地址版本 → 之后才移动 `stable` / `stable-verified-<日期>` 标签、更新本 CHANGELOG、写 GitHub Release(`gh release create`)。 > 测试发现问题 → 改 → 再 `deploy:test`,正式环境不受影响。回滚点 `git reset --hard stable`。 +## v3.26.131(2026-11-30)图库缩略图改 objectURL(修「能加载但很慢」) + +宫格每张缩略图原来都走 `galleryThumb()`:读盘 → base64 → 返回 dataURL。 +164 张 = 164 次 IPC + 每次 20~40KB 字符串,开一次面板就是 3~6MB 字符串搬运。 + +- 新增 `galleryThumbUrl()`:读一次盘、建一个 objectURL,LRU 500 条;重复打开零成本。 +- `thumbFor` 优先走 objectURL,拿不到才退回 dataURL。 +- 缺缩略图的条目 settle 等待 3s → 1.6s,别再拖住整格。 + ## v3.26.130(2026-11-30)插件页显示已安装版本(原来显示的是市场版本) 129 的「插件源」读数证明:加载器读到的就是新版(gallery@1.9.8 / album@1.2.4 / promptlib@1.14.10), diff --git a/app.js b/app.js index 46e7d38..2a9df2d 100644 --- a/app.js +++ b/app.js @@ -7771,7 +7771,7 @@ const tbCenterSeed = (type, refs) => { list: (o) => window.IWBPluginGallery.query(outputs, o), // v3.26.61:缩略图取源顺序(清单 data → images/thumbs → 本地原图 → 远程)在 gallery-sync 里, // 原因是「生图后图库不显示」有一半出在这里 —— 新图 data 还没 hydrate 就只剩远程 url 可退。 - thumb: (name) => (wGallerySync ? wGallerySync.thumbFor(name, { outputs, displayThumbOf: wDisplayThumbOf, galleryThumb: (h) => { const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null; return (F && typeof F.galleryThumb === 'function') ? F.galleryThumb(h) : Promise.resolve('') } }) : ''), + thumb: (name) => (wGallerySync ? wGallerySync.thumbFor(name, { outputs, displayThumbOf: wDisplayThumbOf, galleryThumb: (h) => { const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null; return (F && typeof F.galleryThumb === 'function') ? F.galleryThumb(h) : Promise.resolve('') }, galleryThumbUrl: (h) => { const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null; return (F && typeof F.galleryThumbUrl === 'function') ? F.galleryThumbUrl(h) : Promise.resolve('') } }) : ''), preview: (name) => setPreview({ list: outputs.map((x) => ({ __gallery: true, name: x.name, origIdb: x.origIdb, idb: x.idb, url: x.url, thumb: x.data || null })), idx: Math.max(0, outputs.findIndex((x) => x.name === name)) }), download: async (names) => { const failed = [] diff --git a/package.json b/package.json index 2b7bf83..23fd552 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "image-workbench-web", "private": true, - "version": "3.26.130", + "version": "3.26.131", "description": "Browser-based node canvas image workbench", "scripts": { "build": "node scripts/build.js && node scripts/copy-plugins.js", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 10fcbb5..0f3d8c7 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2014,7 +2014,7 @@ dependencies = [ [[package]] name = "image-workbench" -version = "3.26.130" +version = "3.26.131" dependencies = [ "arboard", "base64 0.22.1", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 929af6c..b2f1d84 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "image-workbench" -version = "3.26.130" +version = "3.26.131" description = "无限画布 · 生图工作台桌面版" authors = ["malongan"] license = "" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index de3507a..b8285ec 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "../node_modules/@tauri-apps/cli/config.schema.json", "productName": "image-workbench", - "version": "3.26.130", + "version": "3.26.131", "identifier": "com.malongan.imageworkbench", "build": { "frontendDist": "../dist", diff --git a/src/gallery-sync.js b/src/gallery-sync.js index 272dd9e..12425b6 100644 --- a/src/gallery-sync.js +++ b/src/gallery-sync.js @@ -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,内核可随时丢弃,直接给 最省。 + // 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) { /* 继续本地副本 */ } } diff --git a/src/storage-file.js b/src/storage-file.js index af5332f..89b343e 100644 --- a/src/storage-file.js +++ b/src/storage-file.js @@ -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 },