cry-synced-db-client 0.1.212 → 0.1.213
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.js
CHANGED
|
@@ -3219,6 +3219,7 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3219
3219
|
let conflictsResolved = 0;
|
|
3220
3220
|
const collectionStats = {};
|
|
3221
3221
|
this.callOnSyncStart({ calledFrom, initialSync: false });
|
|
3222
|
+
const _perCollectionItems = /* @__PURE__ */ new Map();
|
|
3222
3223
|
try {
|
|
3223
3224
|
this.deps.cancelRestUploadTimer();
|
|
3224
3225
|
await this.deps.awaitRestUpload();
|
|
@@ -3297,12 +3298,14 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3297
3298
|
if (!config) return;
|
|
3298
3299
|
const state = collectionState.get(collection);
|
|
3299
3300
|
state.receivedCount += items.length;
|
|
3301
|
+
const _tProcess = performance.now();
|
|
3300
3302
|
const stats = await this.processIncomingServerData(
|
|
3301
3303
|
collection,
|
|
3302
3304
|
config,
|
|
3303
3305
|
items,
|
|
3304
3306
|
state.source
|
|
3305
3307
|
);
|
|
3308
|
+
const _processingMs = performance.now() - _tProcess;
|
|
3306
3309
|
state.conflicts += stats.conflictsResolved;
|
|
3307
3310
|
if (stats.maxTs) {
|
|
3308
3311
|
if (!state.maxTs || this.compareTimestamps(stats.maxTs, state.maxTs) > 0) {
|
|
@@ -3312,16 +3315,24 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3312
3315
|
if (stats.updatedIds.length > 0) {
|
|
3313
3316
|
this.deps.broadcastUpdates({ [collection]: stats.updatedIds });
|
|
3314
3317
|
}
|
|
3315
|
-
|
|
3318
|
+
const isNewColl = !completedCollections.has(collection);
|
|
3319
|
+
if (isNewColl) {
|
|
3316
3320
|
completedCollections.add(collection);
|
|
3317
|
-
this.callbackSafe(this.callbacks.onSyncProgress, {
|
|
3318
|
-
phase: "server",
|
|
3319
|
-
collection,
|
|
3320
|
-
loaded: completedCollections.size,
|
|
3321
|
-
total: syncSpecs.length,
|
|
3322
|
-
items: items.length
|
|
3323
|
-
});
|
|
3324
3321
|
}
|
|
3322
|
+
_perCollectionItems.set(
|
|
3323
|
+
collection,
|
|
3324
|
+
(_perCollectionItems.get(collection) || 0) + items.length
|
|
3325
|
+
);
|
|
3326
|
+
this.callbackSafe(this.callbacks.onSyncProgress, {
|
|
3327
|
+
phase: "server",
|
|
3328
|
+
collection,
|
|
3329
|
+
loaded: completedCollections.size,
|
|
3330
|
+
total: syncSpecs.length,
|
|
3331
|
+
items: items.length,
|
|
3332
|
+
itemsCumulative: _perCollectionItems.get(collection),
|
|
3333
|
+
isNewCollection: isNewColl,
|
|
3334
|
+
processingMs: Math.round(_processingMs)
|
|
3335
|
+
});
|
|
3325
3336
|
},
|
|
3326
3337
|
{
|
|
3327
3338
|
onRequestBytes: (bytes) => {
|
|
@@ -4141,10 +4152,12 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4141
4152
|
}
|
|
4142
4153
|
async processIncomingServerData(collectionName, config, serverData, source = "incremental") {
|
|
4143
4154
|
if (serverData.length === 0) {
|
|
4144
|
-
return { conflictsResolved: 0, maxTs: void 0, updatedIds: [] };
|
|
4155
|
+
return { conflictsResolved: 0, maxTs: void 0, updatedIds: [], dexieMs: 0, inMemMs: 0 };
|
|
4145
4156
|
}
|
|
4146
4157
|
let maxTs;
|
|
4147
4158
|
let conflictsResolved = 0;
|
|
4159
|
+
let totalDexieMs = 0;
|
|
4160
|
+
let totalInMemMs = 0;
|
|
4148
4161
|
const allUpdatedIds = [];
|
|
4149
4162
|
const BATCH = _SyncEngine.SYNC_BATCH_SIZE;
|
|
4150
4163
|
for (let offset = 0; offset < serverData.length; offset += BATCH) {
|
|
@@ -4203,13 +4216,22 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4203
4216
|
}
|
|
4204
4217
|
}
|
|
4205
4218
|
}
|
|
4219
|
+
let _timingDexieMs = 0;
|
|
4220
|
+
let _timingInMemMs = 0;
|
|
4206
4221
|
if (dexieBatch.length > 0) {
|
|
4222
|
+
const _t0 = performance.now();
|
|
4207
4223
|
await this.dexieDb.saveMany(collectionName, dexieBatch);
|
|
4224
|
+
_timingDexieMs = performance.now() - _t0;
|
|
4225
|
+
totalDexieMs += _timingDexieMs;
|
|
4208
4226
|
}
|
|
4209
4227
|
if (inMemSaveBatch.length > 0) {
|
|
4228
|
+
const _t1 = performance.now();
|
|
4210
4229
|
this.deps.writeToInMemBatch(collectionName, inMemSaveBatch, "upsert", {
|
|
4211
4230
|
source
|
|
4212
4231
|
});
|
|
4232
|
+
const _inMemMs = performance.now() - _t1;
|
|
4233
|
+
_timingInMemMs += _inMemMs;
|
|
4234
|
+
totalInMemMs += _inMemMs;
|
|
4213
4235
|
}
|
|
4214
4236
|
if (inMemDeleteIds.length > 0) {
|
|
4215
4237
|
this.deps.writeToInMemBatch(
|
|
@@ -4228,7 +4250,7 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4228
4250
|
lastSyncTs: maxTs
|
|
4229
4251
|
});
|
|
4230
4252
|
}
|
|
4231
|
-
return { conflictsResolved, maxTs, updatedIds: allUpdatedIds };
|
|
4253
|
+
return { conflictsResolved, maxTs, updatedIds: allUpdatedIds, dexieMs: totalDexieMs, inMemMs: totalInMemMs };
|
|
4232
4254
|
}
|
|
4233
4255
|
// ============================================================
|
|
4234
4256
|
// Private Helpers
|
|
@@ -248,6 +248,9 @@ export interface SyncEngineCallbacks {
|
|
|
248
248
|
loaded: number;
|
|
249
249
|
total: number;
|
|
250
250
|
items: number;
|
|
251
|
+
itemsCumulative?: number;
|
|
252
|
+
isNewCollection?: boolean;
|
|
253
|
+
processingMs?: number;
|
|
251
254
|
}) => void;
|
|
252
255
|
onServerSyncStart?: (info: {
|
|
253
256
|
calledFrom?: string;
|
|
@@ -674,6 +674,12 @@ export interface SyncedDbConfig {
|
|
|
674
674
|
loaded: number;
|
|
675
675
|
total: number;
|
|
676
676
|
items: number;
|
|
677
|
+
/** Cumulative items for this collection across all chunks so far */
|
|
678
|
+
itemsCumulative?: number;
|
|
679
|
+
/** True only for the first chunk of a new collection */
|
|
680
|
+
isNewCollection?: boolean;
|
|
681
|
+
/** Processing time for this chunk: Dexie save + InMem write (ms) */
|
|
682
|
+
processingMs?: number;
|
|
677
683
|
}) => void;
|
|
678
684
|
/**
|
|
679
685
|
* Callback when per-collection hydration status changes (hydration end,
|