feat(gallery): 1.9.7 卡片缓存 400→60 + 淘汰摘 src(图库面板开关涨 200MB)
validate / validate (push) Canceled after 0s
validate / validate (push) Canceled after 0s
This commit is contained in:
1 parent
f47f85dfa7
commit
70613a4112
2 files changed
+22
-4
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/gallery",
|
||||
"private": true,
|
||||
"version": "1.9.6",
|
||||
"version": "1.9.7",
|
||||
"description": "图库:右栏图片墙(筛选/多选/预览/插入画布/下载/删除),数据由宿主 gallery 能力提供",
|
||||
"ibwPlugin": {
|
||||
"id": "gallery",
|
||||
|
||||
+21
-3
@@ -468,6 +468,8 @@
|
||||
// 复用时把上轮可能还停在 display:none 的缩略图复位(否则看起来「没图」)
|
||||
var hi = hit.querySelector('img')
|
||||
if (hi && hi.style.display === 'none' && hi.complete && hi.naturalWidth > 0) hi.style.display = ''
|
||||
// v1.9.7:卡片被淘汰时 src 被摘掉了(见下),复用时重新取一次缩略图,否则是张空白卡
|
||||
if (hi && !hi.getAttribute('src') && typeof hit.__iwbBoot === 'function') { try { hit.__iwbBoot() } catch (e5) { /* ignore */ } }
|
||||
return hit
|
||||
}
|
||||
var on = !!picked[it.name]
|
||||
@@ -510,7 +512,7 @@
|
||||
thumbCache[key] = url
|
||||
thumbOrder.push(key)
|
||||
// 上限 400:200+ 张的图库来回滚会把 objectURL 一直攒在内存里
|
||||
while (thumbOrder.length > 400) { var oldK = thumbOrder.shift(); if (oldK && oldK !== key) { try { delete thumbCache[oldK] } catch (e2) { /* ignore */ } } }
|
||||
while (thumbOrder.length > 80) { var oldK = thumbOrder.shift(); if (oldK && oldK !== key) { try { delete thumbCache[oldK] } catch (e2) { /* ignore */ } } }
|
||||
}
|
||||
delete thumbPending[key]
|
||||
return url
|
||||
@@ -583,9 +585,25 @@
|
||||
if (origBadge) box.appendChild(origBadge)
|
||||
if (on) box.appendChild(el('span', { class: 'iwb-history-check', title: '已选中' }))
|
||||
box.__iwbItem = it
|
||||
box.__iwbBoot = boot
|
||||
nodeCache[it.name] = box
|
||||
nodeOrder.push(it.name)
|
||||
while (nodeOrder.length > 400) { var oldN = nodeOrder.shift(); if (oldN && oldN !== it.name) { try { delete nodeCache[oldN] } catch (e3) { /* ignore */ } } }
|
||||
// v1.9.7(Windows 实测:开图库面板涨 ~200MB、关闭后不降):
|
||||
// 原上限 400 张卡,每张都挂着一张已解码的 <img>;淘汰时只从 Map 里 delete,
|
||||
// detached 节点上的解码位图要等 GC 才放。现在 60 张(虚拟列表窗口约 30 张)+ 淘汰时**显式摘 src**。
|
||||
while (nodeOrder.length > 60) {
|
||||
var oldN = nodeOrder.shift()
|
||||
if (!oldN || oldN === it.name) continue
|
||||
try {
|
||||
var oldBox = nodeCache[oldN]
|
||||
if (oldBox) {
|
||||
var oldImg = oldBox.querySelector('img')
|
||||
if (oldImg) oldImg.removeAttribute('src')
|
||||
if (oldBox.parentNode) oldBox.parentNode.removeChild(oldBox)
|
||||
}
|
||||
delete nodeCache[oldN]
|
||||
} catch (e3) { /* ignore */ }
|
||||
}
|
||||
return box
|
||||
}
|
||||
|
||||
@@ -836,4 +854,4 @@
|
||||
})
|
||||
return {}
|
||||
})
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
Reference in new issue
Block a user