Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Fix clean deleted files handler

Hakan Shehu4824d43646a1
diff --git a/apps/desktop/src/main/jobs/clean-deleted-files.ts b/apps/desktop/src/main/jobs/clean-deleted-files.ts
index ca39f36b..29b54cac 100644
--- a/apps/desktop/src/main/jobs/clean-deleted-files.ts
+++ b/apps/desktop/src/main/jobs/clean-deleted-files.ts
@@ -17,8 +17,8 @@ declare module '@/main/jobs' {
export class CleanDeletedFilesJobHandler
implements JobHandler<CleanDeletedFilesInput>
{
- public triggerDebounce = 0;
- public interval = 1000 * 60;
+ public triggerDebounce = 1000;
+ public interval = 1000 * 60 * 10;
public async handleJob(input: CleanDeletedFilesInput) {
await fileService.cleanDeletedFiles(input.userId);
diff --git a/apps/desktop/src/main/services/file-service.ts b/apps/desktop/src/main/services/file-service.ts
index 14d8e4bf..cbc8550f 100644
--- a/apps/desktop/src/main/services/file-service.ts
+++ b/apps/desktop/src/main/services/file-service.ts
@@ -408,7 +408,8 @@ class FileService {
const fileIdMap: Record<string, string> = {};
for (const file of batch) {
- fileIdMap[file.split('_')[0]!] = file;
+ const id = path.parse(file).name;
+ fileIdMap[id] = file;
}
const fileIds = Object.keys(fileIdMap);
@@ -419,29 +420,16 @@ class FileService {
.execute();
for (const fileId of fileIds) {
- if (!fileStates.some((f) => f.file_id === fileId)) {
- const filePath = path.join(
- getWorkspaceFilesDirectoryPath(userId),
- fileIdMap[fileId]!
- );
- fs.rmSync(filePath, { force: true });
-
- const deletedFileState = await workspaceDatabase
- .deleteFrom('file_states')
- .returningAll()
- .where('file_id', '=', fileId)
- .executeTakeFirst();
-
- if (!deletedFileState) {
- continue;
- }
-
- eventBus.publish({
- type: 'file_state_deleted',
- userId,
- fileState: mapFileState(deletedFileState),
- });
+ const fileState = fileStates.find((f) => f.file_id === fileId);
+ if (fileState) {
+ continue;
}
+
+ const filePath = path.join(
+ getWorkspaceFilesDirectoryPath(userId),
+ fileIdMap[fileId]!
+ );
+ fs.rmSync(filePath, { force: true });
}
}
}