@pmate/chat-sdk 0.12.0-next.26 → 0.12.0-next.27
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/lib/runtime/readIndex.js +13 -3
- package/package.json +1 -1
package/lib/runtime/readIndex.js
CHANGED
|
@@ -278,7 +278,7 @@ export class IndexedDbReadIndex {
|
|
|
278
278
|
return this.hydrate(current, this.key(appId, profileId));
|
|
279
279
|
if (current) {
|
|
280
280
|
if (this.migrateLegacy)
|
|
281
|
-
await this.persist(appId, profileId, undefined, current);
|
|
281
|
+
await this.persist(appId, profileId, undefined, current, true);
|
|
282
282
|
return current;
|
|
283
283
|
}
|
|
284
284
|
if (!this.migrateLegacy || this.storageScope === undefined)
|
|
@@ -305,9 +305,11 @@ export class IndexedDbReadIndex {
|
|
|
305
305
|
}
|
|
306
306
|
/** Message bodies are immutable for local read observations: keep them out of
|
|
307
307
|
* profile/cursor writes, and update only changed normalized rows on sync. */
|
|
308
|
-
async persist(appId, profileId, previous, next) {
|
|
309
|
-
if (previous && !this.normalizedStates.has(previous))
|
|
308
|
+
async persist(appId, profileId, previous, next, replaceLegacy = false) {
|
|
309
|
+
if (previous && !this.normalizedStates.has(previous)) {
|
|
310
310
|
previous = undefined;
|
|
311
|
+
replaceLegacy = true;
|
|
312
|
+
}
|
|
311
313
|
const owner = JSON.stringify(this.key(appId, profileId));
|
|
312
314
|
const oldThreads = new Map(previous?.threads.map(thread => [thread.id, thread]) ?? []);
|
|
313
315
|
const nextIds = new Set(next.threads.map(thread => thread.id));
|
|
@@ -352,6 +354,14 @@ export class IndexedDbReadIndex {
|
|
|
352
354
|
await this.positionRows.delete([owner, id]);
|
|
353
355
|
await this.messageRows.where("[owner+thread]").equals([owner, id]).delete();
|
|
354
356
|
}
|
|
357
|
+
// A legacy document can replace the full profile after normalization. Its
|
|
358
|
+
// replacement is authoritative for the row set; discard unreachable bodies
|
|
359
|
+
// in the same transaction before installing the rebuilt normalized records.
|
|
360
|
+
if (replaceLegacy) {
|
|
361
|
+
await this.messageRows.where("owner").equals(owner).delete();
|
|
362
|
+
await this.threadRows.where("owner").equals(owner).delete();
|
|
363
|
+
await this.positionRows.where("owner").equals(owner).delete();
|
|
364
|
+
}
|
|
355
365
|
// Bound each IndexedDB bulk request. A snapshot and its cursor still commit
|
|
356
366
|
// atomically; bounding total snapshot transaction bytes is separate work.
|
|
357
367
|
for (let offset = 0; offset < positionWrites.length; offset += 128)
|
package/package.json
CHANGED