Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: run trash cleanup after sync completion

Abdullah Atta2e79b2c7a293
diff --git a/packages/core/src/api/sync/index.ts b/packages/core/src/api/sync/index.ts
index 064d7825d..03c389073 100644
--- a/packages/core/src/api/sync/index.ts
+++ b/packages/core/src/api/sync/index.ts
@@ -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());
diff --git a/packages/core/src/collections/trash.ts b/packages/core/src/collections/trash.ts
index 027a5d1a6..4df913971 100644
--- a/packages/core/src/collections/trash.ts
+++ b/packages/core/src/collections/trash.ts
@@ -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(