From bad7f0966e48415f8e14b3ea8c94e87a488eaab4 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 26 May 2026 18:16:46 +0530 Subject: [PATCH] Remove dead _updateParentReferencesFromUpdate helper The helper in LiveMap.overrideWithObjectState performed per-diff parentReferences updates during OBJECT_SYNC processing. Every path that invoked it was immediately followed by RealtimeObject._rebuildAllParentReferences (RTO5c10), which unconditionally clears every parentReferences map and re-derives them from the final pool state. The helper's work was therefore overwritten before any external observer could see it. In the tombstone branch, the helper additionally double-called removeParentReference on objects whose parent refs had already been removed by LiveMap.clearData's RTLO4e5 iteration; this was harmless (removeParentReference is idempotent per RTLO3f3a) but wasted work. Also scope-tightens previousDataRef into the only branch that reads it. No spec changes, no public API impact. --- src/plugins/liveobjects/livemap.ts | 45 +----------------------------- 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/src/plugins/liveobjects/livemap.ts b/src/plugins/liveobjects/livemap.ts index a76f63f22e..5f3ae54ea6 100644 --- a/src/plugins/liveobjects/livemap.ts +++ b/src/plugins/liveobjects/livemap.ts @@ -438,13 +438,13 @@ export class LiveMap = Record> return { noop: true }; } - const previousDataRef = this._dataRef; let update: LiveMapUpdate; if (objectState.tombstone) { // tombstone this object and ignore the data from the object state message update = this.tombstone(objectMessage); } else { // otherwise override data for this object with data from the object state + const previousDataRef = this._dataRef; this._createOperationIsMerged = false; // RTLM6b this._clearTimeserial = objectState.map?.clearTimeserial; // RTLM6i this._dataRef = this._liveMapDataFromMapEntries(objectState.map?.entries ?? {}); // RTLM6c @@ -458,9 +458,6 @@ export class LiveMap = Record> update.objectMessage = objectMessage; } - // Update parent references based on the calculated diff - this._updateParentReferencesFromUpdate(update, previousDataRef); - return update; } @@ -1095,44 +1092,4 @@ export class LiveMap = Record> return false; } - - /** - * Update parent references based on the calculated update diff. - */ - private _updateParentReferencesFromUpdate(update: LiveMapUpdate, previousDataRef: LiveMapData): void { - for (const [key, changeType] of Object.entries(update.update)) { - if (changeType === 'removed') { - // Key was removed - remove parent reference from the old object if it was referencing one - const previousEntry = previousDataRef.data.get(key); - if (previousEntry?.data && 'objectId' in previousEntry.data) { - const oldReferencedObject = this._realtimeObject.getPool().get(previousEntry.data.objectId); - if (oldReferencedObject) { - oldReferencedObject.removeParentReference(this, key); - } - } - } - - if (changeType === 'updated') { - // Key was updated - need to handle both removal of old reference and addition of new reference - const previousEntry = previousDataRef.data.get(key); - const newEntry = this._dataRef.data.get(key); - - // Remove old parent reference if there was one - if (previousEntry?.data && 'objectId' in previousEntry.data) { - const oldReferencedObject = this._realtimeObject.getPool().get(previousEntry.data.objectId); - if (oldReferencedObject) { - oldReferencedObject.removeParentReference(this, key); - } - } - - // Add new parent reference if the new value references an object - if (newEntry?.data && 'objectId' in newEntry.data) { - const newReferencedObject = this._realtimeObject.getPool().get(newEntry.data.objectId); - if (newReferencedObject) { - newReferencedObject.addParentReference(this, key); - } - } - } - } - } }