0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-06 12:12:42 +00:00

GC functional, config values now actually used

This commit is contained in:
G.Ambatte
2024-10-07 20:53:32 +13:00
parent 1e38ed8d1f
commit 24bffacaeb

View File

@@ -15,9 +15,8 @@ const DEFAULT_HISTORY_SAVE_DELAYS = {
const DEFAULT_GARBAGE_COLLECT_DELAY = 28 * 24 * 60; const DEFAULT_GARBAGE_COLLECT_DELAY = 28 * 24 * 60;
const HISTORY_SAVE_DELAYS = global.config?.historyData?.HISTORY_SAVE_DELAYS ?? DEFAULT_HISTORY_SAVE_DELAYS; let HISTORY_SAVE_DELAYS = DEFAULT_HISTORY_SAVE_DELAYS;
const GARBAGE_COLLECT_DELAY = global.config?.historyData?.GARBAGE_COLLECT_DELAY ?? DEFAULT_GARBAGE_COLLECT_DELAY; let GARBAGE_COLLECT_DELAY = DEFAULT_GARBAGE_COLLECT_DELAY;
function getKeyBySlot(brew, slot){ function getKeyBySlot(brew, slot){
@@ -48,6 +47,10 @@ function parseBrewForStorage(brew, slot = 0) {
expireAt : new Date() expireAt : new Date()
}; };
if(global.config?.history?.HISTORY_SAVE_DELAYS){
HISTORY_SAVE_DELAYS = global.config?.history?.HISTORY_SAVE_DELAYS;
}
archiveBrew.expireAt.setMinutes(archiveBrew.expireAt.getMinutes() + HISTORY_SAVE_DELAYS[slot]); archiveBrew.expireAt.setMinutes(archiveBrew.expireAt.getMinutes() + HISTORY_SAVE_DELAYS[slot]);
const key = getKeyBySlot(brew, slot); const key = getKeyBySlot(brew, slot);
@@ -128,17 +131,22 @@ export async function updateHistory(brew) {
}; };
}; };
export function versionHistoryGarbageCollection(){ export async function versionHistoryGarbageCollection(){
console.log('Version History Garbage Collection'); if(global.config?.history?.GARBAGE_COLLECT_DELAY != GARBAGE_COLLECT_DELAY) GARBAGE_COLLECT_DELAY = global.config?.history?.GARBAGE_COLLECT_DELAY;
// Object.keys(IDB)
// .filter((key)=>{ await IDB.entries()
// return key.startsWith(HISTORY_PREFIX); .then((entries)=>{
// }) entries.forEach((entry)=>{
// .forEach((key)=>{ const key = entry[0];
// const collectAt = new Date(JSON.parse(IDB.get(key)).savedAt); const value = entry[1];
// collectAt.setMinutes(collectAt.getMinutes() + GARBAGE_COLLECT_DELAY);
// if(new Date() > collectAt){ if(key.startsWith(`${HISTORY_PREFIX}`)) {
// IDB.removeItem(key); const collectAt = new Date(value.savedAt);
// } collectAt.setMinutes(collectAt.getMinutes() + GARBAGE_COLLECT_DELAY);
// }); if(new Date() > collectAt){
IDB.del(key);
};
}
});
});
}; };