Skip to content

refactor(datagrid): drop reloadVersion / lastIdentity counter bridge#933

Merged
datlechin merged 4 commits intomainfrom
refactor/datagrid-phase-d-drop-counter-bridge
Apr 29, 2026
Merged

refactor(datagrid): drop reloadVersion / lastIdentity counter bridge#933
datlechin merged 4 commits intomainfrom
refactor/datagrid-phase-d-drop-counter-bridge

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

Phase D of the DataGrid refactor. Drops the SwiftUI counter-driven reload bridge that's now redundant — Phase C.2 made mutations dispatch Delta directly to NSTableView, so the SwiftUI reloadVersion rerun was a duplicate reload pass.

Net −259 LOC across 12 files, no behavior change.

What's removed

  • lastReapplyVersion field on TableViewCoordinator (already dead, never read or written elsewhere)
  • lastReloadVersion field on TableViewCoordinator
  • versionChanged branch in reloadAndSyncSelection (delta path already covers cell-edit reloads)
  • reloadVersion from DataGridIdentity composition
  • consumeChangedRowIndices from ChangeManaging protocol, AnyChangeManager wrapper, DataChangeManager, StructureChangeManager
  • changedRowIndices field on PendingChanges and StructureChangeManager, plus 14+ insert(...) and removeAll() call sites
  • All matching tests for the dead consume path

Why the visual-state cache still works

The previous versionChanged branch implicitly rebuilt rowVisualStateCache on every cell edit via its second reload. With that gone, commitCellEdit and TableViewCoordinator.applyDelta(.cellChanged / .cellsChanged) now call rebuildVisualStateCache() before the controller dispatch. The cache is guarded by lastVisualStateCacheVersion != changeManager.reloadVersion, so calling it liberally is cheap.

What stays

  • reloadVersion on DataChangeManager and StructureChangeManager — still used by rebuildVisualStateCache's version guard, and by CreateTableView's .onChange for SQL preview regeneration
  • lastIdentity early-return in updateNSView — still useful as a no-op short-circuit for non-data SwiftUI rerenders
  • metadataChanged and paginationChanged branches — no delta-dispatch equivalents yet (parking-lot for a future PR)

Test plan

  • Build clean (xcodebuild ... build)
  • Existing tests pass when run alone (parallel-execution flakes are pre-existing on main)
  • Manual smoke: cell edit shows yellow modified marker
  • Manual smoke: undo clears the marker
  • Manual smoke: Cmd+Shift+N adds a row and starts editing it
  • Manual smoke: switching tables shows the new table's rows (not the previous table's cached values)

Follow-up parking lot (deferred)

  • Drop lastIdentity early-return entirely once the remaining branches (metadataChanged FK reload, paginationChanged scroll) are converted to delta dispatch
  • Replace metadataChanged FK column reload with an explicit delta when FK metadata refreshes
  • Collapse cachedTableRows (mirrors tableRowsProvider() — two sources of truth)

…(Phase D)

Cell edits, row inserts and removals now drive NSTableView through Delta dispatch directly, so the SwiftUI counter-driven reload path is redundant. Removes:

- lastReapplyVersion (already dead)
- lastReloadVersion field on TableViewCoordinator
- versionChanged branch in reloadAndSyncSelection (delta path already covers this)
- reloadVersion field from DataGridIdentity composition
- consumeChangedRowIndices on AnyChangeManager / DataChangeManager / StructureChangeManager
- changedRowIndices accounting on PendingChanges and StructureChangeManager (14 insert calls and the consume/clear sites)

To keep the modified-cell yellow marker correct without the SwiftUI rerun, commitCellEdit and TableViewCoordinator.applyDelta(.cellChanged / .cellsChanged) now call rebuildVisualStateCache before the controller dispatch. This was previously implicit via the versionChanged branch's second reload.

Net -259 LOC. Build green, smoke-tested cell edit/undo, add-row, table switch.
@datlechin datlechin changed the title refactor(datagrid): drop reloadVersion / lastIdentity counter bridge (Phase D) refactor(datagrid): drop reloadVersion / lastIdentity counter bridge Apr 29, 2026
… sweep

The bulk sed deletion of changedRowIndices.insert(...) lines in StructureChangeManager.deleteColumn / deleteIndex / deleteForeignKey left six empty blocks behind: three 'if let rowIndex = workingX.firstIndex(...) { }' blocks where the binding is now unused, and three 'if let rowIndex { for i in rowIndex..<workingX.count { } }' loops with empty bodies. Removed all six.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0bd7e81bb9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 233 to 236
let currentIdentity = DataGridIdentity(
reloadVersion: changeManager.reloadVersion,
schemaVersion: schemaVersion,
metadataVersion: metadataVersion,
paginationVersion: paginationVersion,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include reloadVersion in DataGrid identity checks

Dropping reloadVersion from DataGridIdentity means updateNSView now early-returns for changes that do not alter row/column counts or metadata, even when the underlying ChangeManaging state changed. In this repo, schema undo/redo paths (for example CreateTableGridDelegate.dataGridUndo/Redo calling StructureChangeManager.undo/redo) do not dispatch a Delta, and many of those edits keep the same row/column shape; after this commit, those updates can leave stale cell values/row visual state on screen until a later full reload (query rerun, sort, tab switch).

Useful? React with 👍 / 👎.

@datlechin datlechin merged commit 5343e27 into main Apr 29, 2026
2 checks passed
@datlechin datlechin deleted the refactor/datagrid-phase-d-drop-counter-bridge branch April 29, 2026 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant