mirror of
https://github.com/vladmandic/automatic
synced 2026-09-18 16:54:33 +02:00
Remove old entries from gallery cache
Removes excess thumbnail data when the IndexedDB has at least 200 more entries than is loaded by the gallery.
This commit is contained in:
@@ -75,6 +75,46 @@ async function put(record) {
|
||||
});
|
||||
}
|
||||
|
||||
async function idbGetAllKeys() {
|
||||
if (!db) return null;
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = db
|
||||
.transaction("thumbs")
|
||||
.objectStore("thumbs")
|
||||
.getAllKeys();
|
||||
request.onsuccess = () => resolve(request.result);
|
||||
request.onerror = (evt) => reject(evt);
|
||||
});
|
||||
}
|
||||
|
||||
async function idbClean(keepSet) {
|
||||
if (!db) return null;
|
||||
if (!keepSet instanceof Set) {
|
||||
console.error("IndexedDB cleaning function must be given a Set() of hashes to keep");
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
let counter = 0;
|
||||
const request = db
|
||||
.transaction("thumbs", "readwrite")
|
||||
.objectStore("thumbs")
|
||||
.openCursor();
|
||||
request.onsuccess = (evt) => {
|
||||
const cursor = evt.target.result;
|
||||
if (cursor) {
|
||||
if (!keepSet.has(cursor.key)) {
|
||||
cursor.delete();
|
||||
counter++;
|
||||
}
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
resolve(counter);
|
||||
}
|
||||
};
|
||||
request.onerror = (evt) => reject(evt);
|
||||
});
|
||||
}
|
||||
|
||||
window.idbAdd = add;
|
||||
window.idbDel = del;
|
||||
window.idbGet = get;
|
||||
|
||||
Reference in New Issue
Block a user