Skip to content

Commit

Permalink
Only run regular GC every 24hrs.
Browse files Browse the repository at this point in the history
  • Loading branch information
FMaz008 committed May 16, 2024
1 parent 49e013c commit 31de1a6
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions scripts/HiddenListMgr.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//No JQuery

class HiddenListMgr {
arrHidden = [];
arrChanges = [];
listLoaded = false;
broadcast = null;

constructor() {
this.arrHidden = [];
this.arrChanges = [];
this.listLoaded = false;

this.broadcast = new BroadcastChannel("vine_helper");

showRuntime("HIDDENMGR: Loading list");
Expand Down Expand Up @@ -189,22 +188,32 @@ class HiddenListMgr {
}

//Delete items older than 90 days
const originalLength = this.arrHidden.length;
let expiredDate = new Date();
expiredDate.setDate(expiredDate.getDate() - 90);
let timestampNow = Math.floor(Date.now() / 1000);
if (appSettings.hiddenTab.lastGC == undefined) {
appSettings.hiddenTab.lastGC = timestampNow;
saveSettings(); //preboot.js
}

let idx = 0;
while (idx < this.arrHidden.length) {
let itemDate = new Date(this.arrHidden[idx].date); // Parse current item's date
if (isNaN(itemDate.getTime())) {
this.arrHidden[idx].date = new Date().toString();
} else if (itemDate < expiredDate) {
this.arrHidden.splice(idx, 1);
} else {
++idx;
if (appSettings.hiddenTab.lastGC < timestampNow - 24 * 60 * 60) {
const originalLength = this.arrHidden.length;
let expiredDate = new Date();
expiredDate.setDate(expiredDate.getDate() - 90);

let idx = 0;
while (idx < this.arrHidden.length) {
let itemDate = new Date(this.arrHidden[idx].date); // Parse current item's date
if (isNaN(itemDate.getTime())) {
this.arrHidden[idx].date = new Date().toString();
} else if (itemDate < expiredDate) {
this.arrHidden.splice(idx, 1);
} else {
++idx;
}
}
}

appSettings.hiddenTab.lastGC = timestampNow;
saveSettings(); //preboot.js
}
if (this.arrHidden.length != originalLength) {
this.saveList();
}
Expand Down

0 comments on commit 31de1a6

Please sign in to comment.