Open-source and local-first Slack and Notion alternative that puts you in control of your data
TypeScript chatchat-applicationcrdteditorelectronknowledge-baselocal-firstnotionnotion-alternativerealtime-collaborationself-hostedslacksqliteteam-collaborationwikiyjs
Skip entry update if there are no changes
Hakan Shehu852a1e4ed710
diff --git a/apps/desktop/src/main/mutations/pages/page-content-update.ts b/apps/desktop/src/main/mutations/pages/page-content-update.tsindex f2244ade..ecfca9c6 100644--- a/apps/desktop/src/main/mutations/pages/page-content-update.ts+++ b/apps/desktop/src/main/mutations/pages/page-content-update.ts@@ -19,6 +19,12 @@ export class PageContentUpdateMutationHandler): Promise<PageContentUpdateMutationOutput> {const workspace = this.getWorkspace(input.accountId, input.workspaceId);+ if (isEqual(input.before.content, input.after.content)) {+ return {+ success: true,+ };+ }+const result = await workspace.entries.updateEntry<PageAttributes>(input.pageId,(attributes) => {diff --git a/apps/desktop/src/main/mutations/records/record-content-update.ts b/apps/desktop/src/main/mutations/records/record-content-update.tsindex 75fa05e6..2812332d 100644--- a/apps/desktop/src/main/mutations/records/record-content-update.ts+++ b/apps/desktop/src/main/mutations/records/record-content-update.ts@@ -18,6 +18,13 @@ export class RecordContentUpdateMutationHandlerinput: RecordContentUpdateMutationInput): Promise<RecordContentUpdateMutationOutput> {const workspace = this.getWorkspace(input.accountId, input.workspaceId);++ if (isEqual(input.before.content, input.after.content)) {+ return {+ success: true,+ };+ }+const result = await workspace.entries.updateEntry<RecordAttributes>(input.recordId,(attributes) => {diff --git a/apps/desktop/src/main/services/workspaces/entry-service.ts b/apps/desktop/src/main/services/workspaces/entry-service.tsindex 922207a6..fc33c5b4 100644--- a/apps/desktop/src/main/services/workspaces/entry-service.ts+++ b/apps/desktop/src/main/services/workspaces/entry-service.ts@@ -98,6 +98,10 @@ export class EntryService {input.attributes);+ if (!update) {+ return;+ }+const createdAt = new Date().toISOString();const transactionId = generateId(IdType.Transaction);const text = extractEntryText(input.id, input.attributes);@@ -263,6 +267,10 @@ export class EntryService {return 'unauthorized';}+ if (!update) {+ return 'success';+ }+const text = extractEntryText(entryId, updatedAttributes);const { updatedEntry, createdMutation } = await this.workspace.databasediff --git a/apps/server/src/services/entry-service.ts b/apps/server/src/services/entry-service.tsindex 69c975a0..8ded3f94 100644--- a/apps/server/src/services/entry-service.ts+++ b/apps/server/src/services/entry-service.ts@@ -69,6 +69,11 @@ class EntryService {entryAttributesSchema,input.attributes);++ if (!update) {+ return null;+ }+const attributes = ydoc.getAttributes<EntryAttributes>();const attributesJson = JSON.stringify(attributes);@@ -188,6 +193,10 @@ class EntryService {updatedAttributes);+ if (!update) {+ return { type: 'success', output: null };+ }+const attributes = ydoc.getAttributes<EntryAttributes>();const attributesJson = JSON.stringify(attributes);diff --git a/packages/crdt/src/index.ts b/packages/crdt/src/index.tsindex 7e237671..b44b215a 100644--- a/packages/crdt/src/index.ts+++ b/packages/crdt/src/index.ts@@ -39,7 +39,7 @@ export class YDoc {public updateAttributes(schema: ZodSchema,attributes: z.infer<typeof schema>- ): Uint8Array {+ ): Uint8Array | null {if (!schema.safeParse(attributes).success) {throw new Error('Invalid attributes', schema.safeParse(attributes).error);}@@ -68,7 +68,11 @@ export class YDoc {this.doc.off('update', onUpdateCallback);- if (updates.length === 0 || updates.length > 1) {+ if (updates.length === 0) {+ return null;+ }++ if (updates.length > 1) {throw new Error('Invalid number of updates');}diff --git a/scripts/src/seed/node-generator.ts b/scripts/src/seed/node-generator.tsindex 2bc1f68e..4a7b0d81 100644--- a/scripts/src/seed/node-generator.ts+++ b/scripts/src/seed/node-generator.ts@@ -919,6 +919,9 @@ export class NodeGenerator {): LocalCreateTransaction {const ydoc = new YDoc();const update = ydoc.updateAttributes(entryAttributesSchema, attributes);+ if (!update) {+ throw new Error('Failed to create transaction');+ }return {id: generateId(IdType.Transaction),