Remove dead _updateParentReferencesFromUpdate helper#2234
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe ChangesLiveMap state override refactoring
🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
d424b0a to
bad7f09
Compare
|
I think it's worth having a top-level comment on |
|
Also could you please re-check the spec point references in the PR description and commit message against spec |
|
You could also argue that |
I have cross checked multiple times whether |
There was a problem hiding this comment.
Pull request overview
Removes the dead _updateParentReferencesFromUpdate private helper from LiveMap and its sole call site in overrideWithObjectState. Every invocation path of overrideWithObjectState is part of the OBJECT_SYNC flow (RTO5c), which immediately follows up with RealtimeObject._rebuildAllParentReferences (RTO5c10) — clearing and re-deriving all parent references from pool state — making the helper's work redundant. previousDataRef is also scope-tightened into the else branch where it's actually consumed.
Changes:
- Remove call to
_updateParentReferencesFromUpdatefromoverrideWithObjectState. - Delete the private
_updateParentReferencesFromUpdatemethod. - Move
previousDataRefdeclaration inside the non-tombstone branch.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Not sure I understand your reply here — I wasn't disputing the changes of this PR, I was making a further point about |
Summary
Removes the
_updateParentReferencesFromUpdatehelper fromLiveMapalong with its sole call site insideoverrideWithObjectState. The helper was dead weight: every code path that invoked it was immediately followed byRealtimeObject._rebuildAllParentReferences(spec'd atRTO5c10), which unconditionally clears everyparentReferencesmap and re-derives them from scratch based on the final post-sync pool state. The helper's intermediate updates were always overwritten before any external observer could see them.Why this was dead code
_updateParentReferencesFromUpdatehad exactly one call site:LiveMap.overrideWithObjectState. That method, in turn, is invoked from only three places — all of them inside the OBJECT_SYNC processing flow underRTO5c:RealtimeObject._applyObjectSync(existing object)RTO5c1a1LiveCounter.fromObjectStatefactoryRTO5c1b1aLiveMap.fromObjectStatefactoryRTO5c1b1bAfter
RTO5c1/RTO5c2finish,RTO5c10(_rebuildAllParentReferences) executes unconditionally:RTO5c10a:clearParentReferences()on every object in the pool.RTO5c10b: re-iterate everyLiveMapand re-establish parent refs viaaddParentReferencefor each objectId-valued entry.So any parent refs set by
_updateParentReferencesFromUpdateinsideoverrideWithObjectStatewere wiped byRTO5c10aand re-derived byRTO5c10bbefore sync completion was visible to subscribers.Tombstone branch — also redundant
In the tombstone path (
update = this.tombstone(objectMessage)),LiveObject.tombstone()callsclearData(). ForLiveMap,clearData()is overridden to iterate every entry and callremoveParentReferenceperRTLO4e5— before the data is zeroed. By the timeoverrideWithObjectStatereached_updateParentReferencesFromUpdate, all parent refs were already cleaned. The helper would iterate the'removed'diff keys and callremoveParentReferenceagain on the same objects — a harmless no-op (removeParentReferenceis idempotent when the parent is absent perRTLO3f3a) but wasted work.What changed
src/plugins/liveobjects/livemap.ts:LiveMap.overrideWithObjectState(was lines 461–462).previousDataRef: moved its declaration inside theelsebranch ofoverrideWithObjectStatesince it's only consumed there (by_updateFromDataDiff). The tombstone branch never reads it.Total: 1 insertion, 44 deletions.
Other parent-ref maintenance is unaffected
Outside the sync flow,
parentReferencescontinues to be maintained by the per-operation handlers, each with its own spec coverage:MAP_SET→RTLM7a2f(remove old) andRTLM7i(add new)MAP_REMOVE→RTLM8a2eMAP_CLEAR→RTLM24e1cLiveMaptombstone →RTLO4e5RTO5c10b1None of these call the removed helper.
Spec impact
None.
RTLM6(overrideWithObjectState) doesn't mentionparentReferencesmaintenance, and the operation handlers above already cover every parent-ref mutation the SDK is required to perform.Test plan
npm run build:liveobjects— passes (TypeScript compiles cleanly).npm run lint— passes (only pre-existing warnings inreact-hooksfakes, unrelated)._updateParentReferencesFromUpdatereturns zero hits after the change.npm test), in particulartest/realtime/liveobjects.test.js, which exercises the OBJECT_SYNC flow extensively.LiveMapreferences and path-based subscriptions (RTPO19) still emit the expected events — these end-states depend onRTO5c10, which is unchanged.Risk
Low. The diff is a pure deletion in one file, the method is
private(no external callers possible), and the call-graph audit confirms every invocation path runsRTO5c10immediately afterward. Rollback is a single-commit revert.🤖 Generated with Claude Code
Summary by CodeRabbit