Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(nbstore): check before save empty update (#10304)

EYHN5042d9f6444b
diff --git a/packages/common/nbstore/src/sync/doc/peer.ts b/packages/common/nbstore/src/sync/doc/peer.ts
index a12f5ddd71..a71d1a7b9b 100644
--- a/packages/common/nbstore/src/sync/doc/peer.ts
+++ b/packages/common/nbstore/src/sync/doc/peer.ts
@@ -437,13 +437,15 @@ export class DocSyncPeer {
data.length > 0 ? await this.mergeUpdates(data) : new Uint8Array();
throwIfAborted(signal);
- await this.local.pushDocUpdate(
- {
- docId,
- bin: update,
- },
- this.uniqueId
- );
+ if (!isEmptyUpdate(update)) {
+ await this.local.pushDocUpdate(
+ {
+ docId,
+ bin: update,
+ },
+ this.uniqueId
+ );
+ }
throwIfAborted(signal);
await this.syncMetadata.setPeerPulledRemoteClock(this.peerId, {
diff --git a/packages/frontend/core/src/modules/userspace/entities/user-db-engine.ts b/packages/frontend/core/src/modules/userspace/entities/user-db-engine.ts
index 04c590ee61..416201e0ef 100644
--- a/packages/frontend/core/src/modules/userspace/entities/user-db-engine.ts
+++ b/packages/frontend/core/src/modules/userspace/entities/user-db-engine.ts
@@ -1,5 +1,5 @@
-import { IndexedDBDocStorage } from '@affine/nbstore/idb';
-import { SqliteDocStorage } from '@affine/nbstore/sqlite';
+import { IndexedDBDocStorage, IndexedDBSyncStorage } from '@affine/nbstore/idb';
+import { SqliteDocStorage, SqliteSyncStorage } from '@affine/nbstore/sqlite';
import type { StoreClient } from '@affine/nbstore/worker/client';
import { Entity } from '@toeverything/infra';
@@ -16,6 +16,10 @@ export class UserDBEngine extends Entity<{
BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS
? SqliteDocStorage
: IndexedDBDocStorage;
+ SyncStorageType =
+ BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS
+ ? SqliteSyncStorage
+ : IndexedDBSyncStorage;
canGracefulStop() {
// TODO(@eyhn): Implement this
@@ -40,6 +44,14 @@ export class UserDBEngine extends Entity<{
type: 'userspace',
},
},
+ sync: {
+ name: this.SyncStorageType.identifier,
+ opts: {
+ id: `${serverService.server.id}:` + this.userId,
+ type: 'userspace',
+ flavour: serverService.server.id,
+ },
+ },
},
remotes: {
cloud: {