auto clean sync plans

This commit is contained in:
fyears
2022-04-06 00:35:21 +08:00
parent b3c107ce58
commit bb21714b45
2 changed files with 64 additions and 0 deletions
+22
View File
@@ -26,6 +26,7 @@ import {
InternalDBs,
insertLoggerOutputByVault,
clearExpiredLoggerOutputRecords,
clearExpiredSyncPlanRecords,
} from "./localdb";
import { RemoteClient } from "./remote";
import {
@@ -419,6 +420,9 @@ export default class RemotelySavePlugin extends Plugin {
this.addOutputToDBIfSet();
this.enableAutoClearOutputToDBHistIfSet();
// must AFTER preparing DB
this.enableAutoClearSyncPlanHist();
this.syncStatus = "idle";
this.registerEvent(
@@ -948,4 +952,22 @@ export default class RemotelySavePlugin extends Plugin {
this.registerInterval(intervalID);
});
}
enableAutoClearSyncPlanHist() {
const initClearSyncPlanHistAfterMilliseconds = 1000 * 45;
const autoClearSyncPlanHistAfterMilliseconds = 1000 * 60 * 5;
this.app.workspace.onLayoutReady(() => {
// init run
window.setTimeout(() => {
clearExpiredSyncPlanRecords(this.db);
}, initClearSyncPlanHistAfterMilliseconds);
// scheduled run
const intervalID = window.setInterval(() => {
clearExpiredSyncPlanRecords(this.db);
}, autoClearSyncPlanHistAfterMilliseconds);
this.registerInterval(intervalID);
});
}
}