core: run trash cleanup after sync completion

This commit is contained in:
Abdullah Atta
2025-03-26 13:44:16 +05:00
parent 4e4990bd98
commit 2e79b2c7a2
2 changed files with 7 additions and 3 deletions

View File

@@ -286,7 +286,7 @@ class Sync {
// refresh monographs
await this.db.monographs.refresh().catch(this.logger.error);
// update trash cache
await this.db.trash.buildCache();
await this.db.trash.cleanup();
this.logger.info("Stopping sync");
await this.db.setLastSynced(Date.now());

View File

@@ -55,7 +55,6 @@ export default class Trash {
async init() {
await this.buildCache();
await this.cleanup();
}
async buildCache() {
@@ -92,7 +91,11 @@ export default class Trash {
const duration = this.db.settings.getTrashCleanupInterval();
if (duration === -1 || !duration) return;
const maxMs = dayjs().subtract(duration, "days").toDate().getTime();
const maxMs = dayjs()
.startOf("day")
.subtract(duration, "days")
.toDate()
.getTime();
const expiredItems = await this.db
.sql()
.selectNoFrom((eb) => [
@@ -120,6 +123,7 @@ export default class Trash {
);
await this._delete(noteIds, notebookIds);
await this.buildCache();
}
async add(