Skip to content

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

Fixes and improvements for sync

Hakan Shehu075c6405bacd
diff --git a/desktop/src/main/synchronizer.ts b/desktop/src/main/synchronizer.ts
index ce722469..8b2d48ab 100644
--- a/desktop/src/main/synchronizer.ts
+++ b/desktop/src/main/synchronizer.ts
@@ -142,59 +142,63 @@ class Synchronizer {
credentials.userId,
);
- const changes = await workspaceDatabase
- .selectFrom('changes')
- .selectAll()
- .orderBy('id asc')
- .limit(20)
- .execute();
-
- if (changes.length === 0) {
- return;
- }
+ let hasMoreChanges = true;
+ while (hasMoreChanges) {
+ const changes = await workspaceDatabase
+ .selectFrom('changes')
+ .selectAll()
+ .orderBy('id asc')
+ .limit(20)
+ .execute();
- const { data } = await httpClient.post<ServerSyncResponse>(
- `/v1/sync/${credentials.workspaceId}`,
- {
- changes: changes,
- },
- {
- serverDomain: credentials.serverDomain,
- serverAttributes: credentials.serverAttributes,
- token: credentials.token,
- },
- );
+ if (changes.length === 0) {
+ hasMoreChanges = false;
+ break;
+ }
- const syncedChangeIds: number[] = [];
- const unsyncedChangeIds: number[] = [];
- for (const result of data.results) {
- if (result.status === 'success') {
- syncedChangeIds.push(result.id);
- } else {
- unsyncedChangeIds.push(result.id);
+ const { data } = await httpClient.post<ServerSyncResponse>(
+ `/v1/sync/${credentials.workspaceId}`,
+ {
+ changes: changes,
+ },
+ {
+ serverDomain: credentials.serverDomain,
+ serverAttributes: credentials.serverAttributes,
+ token: credentials.token,
+ },
+ );
+
+ const syncedChangeIds: number[] = [];
+ const unsyncedChangeIds: number[] = [];
+ for (const result of data.results) {
+ if (result.status === 'success') {
+ syncedChangeIds.push(result.id);
+ } else {
+ unsyncedChangeIds.push(result.id);
+ }
}
- }
- if (syncedChangeIds.length > 0) {
- await workspaceDatabase
- .deleteFrom('changes')
- .where('id', 'in', syncedChangeIds)
- .execute();
- }
+ if (syncedChangeIds.length > 0) {
+ await workspaceDatabase
+ .deleteFrom('changes')
+ .where('id', 'in', syncedChangeIds)
+ .execute();
+ }
- if (unsyncedChangeIds.length > 0) {
- await workspaceDatabase
- .updateTable('changes')
- .set((eb) => ({ retry_count: eb('retry_count', '+', 1) }))
- .where('id', 'in', unsyncedChangeIds)
- .execute();
+ if (unsyncedChangeIds.length > 0) {
+ await workspaceDatabase
+ .updateTable('changes')
+ .set((eb) => ({ retry_count: eb('retry_count', '+', 1) }))
+ .where('id', 'in', unsyncedChangeIds)
+ .execute();
- //we just delete changes that have failed to sync for more than 5 times.
- //in the future we might need to revert the change locally.
- await workspaceDatabase
- .deleteFrom('changes')
- .where('retry_count', '>=', 5)
- .execute();
+ //we just delete changes that have failed to sync for more than 5 times.
+ //in the future we might need to revert the change locally.
+ await workspaceDatabase
+ .deleteFrom('changes')
+ .where('retry_count', '>=', 5)
+ .execute();
+ }
}
}
}
diff --git a/server/src/api.ts b/server/src/api.ts
index 4a94e59b..606d50ee 100644
--- a/server/src/api.ts
+++ b/server/src/api.ts
@@ -15,7 +15,11 @@ export const initApi = () => {
const app = express();
const port = 3000;
- app.use(express.json());
+ app.use(
+ express.json({
+ limit: '50mb',
+ }),
+ );
app.use(cors());
app.get('/', (_: Request, res: Response) => {