Skip to content

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

File optimizations

Hakan Shehu9a0ad901377e
diff --git a/apps/desktop/src/main/scheduler.ts b/apps/desktop/src/main/scheduler.ts
index d04cea52..57946fcc 100644
--- a/apps/desktop/src/main/scheduler.ts
+++ b/apps/desktop/src/main/scheduler.ts
@@ -393,6 +393,15 @@ class Scheduler {
type: 'download_files',
userId: event.userId,
});
+ } else if (event.type === 'file_updated') {
+ this.trigger({
+ type: 'upload_files',
+ userId: event.userId,
+ });
+ this.trigger({
+ type: 'download_files',
+ userId: event.userId,
+ });
} else if (event.type === 'file_deleted') {
this.trigger({
type: 'clean_deleted_files',
diff --git a/apps/desktop/src/main/services/file-service.ts b/apps/desktop/src/main/services/file-service.ts
index 25332d28..7778d861 100644
--- a/apps/desktop/src/main/services/file-service.ts
+++ b/apps/desktop/src/main/services/file-service.ts
@@ -3,6 +3,7 @@ import {
CreateDownloadOutput,
CreateUploadOutput,
extractFileType,
+ FileStatus,
SyncFileData,
SyncFileInteractionData,
SyncFileTombstoneData,
@@ -158,7 +159,7 @@ class FileService {
const filesDir = getWorkspaceFilesDirectoryPath(userId);
for (const upload of uploads) {
- if (upload.upload_retries >= 5) {
+ if (upload.upload_retries >= 10) {
await workspaceDatabase
.updateTable('file_states')
.set({
@@ -186,6 +187,26 @@ class FileService {
continue;
}
+ if (file.version === BigInt(0)) {
+ // file is not synced with the server, we need to wait for the sync to complete
+ continue;
+ }
+
+ if (file.status === FileStatus.Ready) {
+ // file is already uploaded to the server
+ await workspaceDatabase
+ .updateTable('file_states')
+ .set({
+ upload_status: UploadStatus.Completed,
+ upload_progress: 100,
+ updated_at: new Date().toISOString(),
+ })
+ .where('file_id', '=', file.id)
+ .execute();
+
+ continue;
+ }
+
const filePath = path.join(filesDir, `${file.id}${file.extension}`);
if (!fs.existsSync(filePath)) {