perf(tree-view-table-layout): PATCH only the rows that actually changed on drag-save#321
Open
seltzdesign wants to merge 1 commit into
Open
perf(tree-view-table-layout): PATCH only the rows that actually changed on drag-save#321seltzdesign wants to merge 1 commit into
seltzdesign wants to merge 1 commit into
Conversation
…ed on drag-save
saveEdits re-PATCHed every edited row on every drag (600+ requests on a large tree), most
no-ops, and a reparent could sit behind them so a fast reload raced the parent write.
- diff each field against the current item; build a changed-only payload (skip no-op rows)
- normalise m2o values before comparing (object {pk} / scalar / null)
- send parent edits first so a reparent persists ahead of the minimal sort updates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every drag (reorder or reparent) saves by PATCHing every edited row, even when a row's payload is identical to what is already in the database. On a moderately sized tree this is hundreds of redundant write requests per drag. Two real consequences:
parent) has been persisted, so the reparent appears to be lost.Root cause
saveEditsinsrc/index.tsloops overObject.entries(edits)and unconditionally PATCHes each row's full payload. There is no comparison against the current value, so unchanged sort keys are written back identically, and there is no ordering, so a structural change (parent) has no priority over bulk sort-position updates.Fix
In
saveEdits:items.value) and build achangedpayload containing only fields whose value actually differs. M2O values are normalised before comparison via a smallrelKeyhelper (handles the{ [pk]: ... }object form, the scalar-key form, andnull) so an unchanged parent expressed in a different shape is not treated as a change. Rows with no real change are skipped entirely (no PATCH).Verification
parentchange first; a fast reload immediately after the drag keeps the new parent.No change to the on-disk result of a save — only which requests are sent, and in what order.