@abraca/dabra 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -933,6 +933,7 @@ declare class OfflineStore {
933
933
  * per-server, preventing cross-server data contamination.
934
934
  */
935
935
  constructor(docId: string, serverOrigin?: string);
936
+ private dbPromise;
936
937
  private getDb;
937
938
  persistUpdate(update: Uint8Array): Promise<void>;
938
939
  getPendingUpdates(): Promise<Uint8Array[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/dabra",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "abracadabra provider",
5
5
  "keywords": [
6
6
  "abracadabra",
@@ -188,12 +188,16 @@ export class AbracadabraProvider extends HocuspocusProvider {
188
188
  private async _initFromOfflineStore(): Promise<void> {
189
189
  if (!this.offlineStore) return;
190
190
 
191
- const snapshot = await this.offlineStore.getDocSnapshot().catch(() => null);
191
+ // Fetch snapshot and pending updates in parallel — each call opens the
192
+ // IDB database, so running them concurrently roughly halves the latency.
193
+ const [snapshot, pending] = await Promise.all([
194
+ this.offlineStore.getDocSnapshot().catch(() => null),
195
+ this.offlineStore.getPendingUpdates().catch(() => []),
196
+ ]);
197
+
192
198
  if (snapshot) {
193
199
  Y.applyUpdate(this.document, snapshot, this.offlineStore);
194
200
  }
195
-
196
- const pending = await this.offlineStore.getPendingUpdates().catch(() => []);
197
201
  for (const update of pending) {
198
202
  Y.applyUpdate(this.document, update, this.offlineStore);
199
203
  }
@@ -77,12 +77,18 @@ export class OfflineStore {
77
77
  this.storeKey = serverOrigin ? `${serverOrigin}/${docId}` : docId;
78
78
  }
79
79
 
80
- private async getDb(): Promise<IDBDatabase | null> {
81
- if (!idbAvailable()) return null;
82
- if (!this.db) {
83
- this.db = await openDb(this.storeKey).catch(() => null);
80
+ private dbPromise: Promise<IDBDatabase | null> | null = null;
81
+
82
+ private getDb(): Promise<IDBDatabase | null> {
83
+ if (!idbAvailable()) return Promise.resolve(null);
84
+ if (!this.dbPromise) {
85
+ // Cache the promise so concurrent callers share a single open operation.
86
+ this.dbPromise = openDb(this.storeKey).catch(() => null).then(db => {
87
+ this.db = db;
88
+ return db;
89
+ });
84
90
  }
85
- return this.db;
91
+ return this.dbPromise;
86
92
  }
87
93
 
88
94
  // ── Pending (unsynced) updates ────────────────────────────────────────────