Skip to content

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

web: remove orphaned attachments on app launch

Abdullah Attaf2402cf0867f
diff --git a/apps/web/src/app-effects.tsx b/apps/web/src/app-effects.tsx
index faeafac5e..750281d8a 100644
--- a/apps/web/src/app-effects.tsx
+++ b/apps/web/src/app-effects.tsx
@@ -70,6 +70,8 @@ export default function AppEffects() {
await scheduleBackups();
await scheduleFullBackups();
await scheduleExpiredNotesDeletion();
+
+ db.attachments.removeOrphaned().catch(logger.error);
if (useSettingStore.getState().isFullOfflineMode)
// NOTE: we deliberately don't await here because we don't want to pause execution.
db.attachments.cacheAttachments().catch(logger.error);
diff --git a/packages/core/src/collections/trash.ts b/packages/core/src/collections/trash.ts
index 30e4b2fb3..087fcfa6d 100644
--- a/packages/core/src/collections/trash.ts
+++ b/packages/core/src/collections/trash.ts
@@ -30,7 +30,6 @@ import {
import { sql } from "@streetwriters/kysely";
import { MAX_SQL_PARAMETERS } from "../database/sql-collection.js";
import { withSubNotebooks } from "./notebooks.js";
-import { logger } from "../logger.js";
export default class Trash {
collections = ["notes", "notebooks"] as const;
@@ -124,15 +123,6 @@ export default class Trash {
);
await this._delete(noteIds, notebookIds);
- this.db.attachments
- .removeOrphaned()
- .catch((e) =>
- logger.error(
- e,
- "Error removing orphaned attachments during trash cleanup"
- )
- );
-
await this.buildCache();
}