mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
core: run trash cleanup after sync completion
This commit is contained in:
@@ -286,7 +286,7 @@ class Sync {
|
|||||||
// refresh monographs
|
// refresh monographs
|
||||||
await this.db.monographs.refresh().catch(this.logger.error);
|
await this.db.monographs.refresh().catch(this.logger.error);
|
||||||
// update trash cache
|
// update trash cache
|
||||||
await this.db.trash.buildCache();
|
await this.db.trash.cleanup();
|
||||||
|
|
||||||
this.logger.info("Stopping sync");
|
this.logger.info("Stopping sync");
|
||||||
await this.db.setLastSynced(Date.now());
|
await this.db.setLastSynced(Date.now());
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ export default class Trash {
|
|||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
await this.buildCache();
|
await this.buildCache();
|
||||||
await this.cleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async buildCache() {
|
async buildCache() {
|
||||||
@@ -92,7 +91,11 @@ export default class Trash {
|
|||||||
const duration = this.db.settings.getTrashCleanupInterval();
|
const duration = this.db.settings.getTrashCleanupInterval();
|
||||||
if (duration === -1 || !duration) return;
|
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
|
const expiredItems = await this.db
|
||||||
.sql()
|
.sql()
|
||||||
.selectNoFrom((eb) => [
|
.selectNoFrom((eb) => [
|
||||||
@@ -120,6 +123,7 @@ export default class Trash {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await this._delete(noteIds, notebookIds);
|
await this._delete(noteIds, notebookIds);
|
||||||
|
await this.buildCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
async add(
|
async add(
|
||||||
|
|||||||
Reference in New Issue
Block a user