Skip to content

refactor(datagrid): collapse cachedTableRows mirror into tableRowsProvider() reads#934

Merged
datlechin merged 1 commit intomainfrom
refactor/datagrid-collapse-cached-tablerows
Apr 29, 2026
Merged

refactor(datagrid): collapse cachedTableRows mirror into tableRowsProvider() reads#934
datlechin merged 1 commit intomainfrom
refactor/datagrid-collapse-cached-tablerows

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

Drops the cachedTableRows stored property on TableViewCoordinator. It was a mirror of what tableRowsProvider() returns, kept in sync via four writers (initial load, updateNSView, updateCache, releaseData). Parking-lot item from PR #931 — under it, every reader had to trust the cache had been refreshed, and a missing refresh produced stale-value bugs.

What changed

Each reader now captures the live rows once at the top of its scope:

  • persistColumnLayoutToStorage
  • updateCache (the only legitimate cache update — cachedRowCount / cachedColumnCount still derived)
  • releaseData (just drops the now-removed field reset)
  • DataGridView+CellPaste (anchor column count check)
  • DataGridView+Sort (sortDescriptorsDidChange + menuNeedsUpdate header context menu)
  • DataGridView+RowActions (undoInsertRow no longer needs the explicit refresh)

Net −6 LOC, one fewer field on the coordinator, no possibility of cache/source drift.

Test plan

  • Build clean
  • Existing tests pass (EvictionTests, TableRowsMutationTests, DataGridIdentityTests)
  • Manual: open table — data displays
  • Manual: right-click column header — menu and "Display As" submenu show correct column name
  • Manual: click column header — sort works
  • Manual: paste TSV into cell selection — cells overwrite
  • Manual: add row + undo — clears correctly

Follow-up parking lot (deferred)

  • MainEditorContentView.resolvedTableRowsForTab and resolvedTableRows(for:) overlap; consolidate
  • sortCache (sync, small) and coordinator.querySortCache (async, large) cache the same shape with different keys; merge
  • Phase D-b: drop lastIdentity early-return + convert metadataChanged (FK reload) and paginationChanged (scroll-to-top) to delta dispatch

…vider() reads

Removes the cachedTableRows stored property on TableViewCoordinator. It mirrored what tableRowsProvider() returns and was kept in sync via four writers (initial load, updateNSView, updateCache, releaseData). The two-sources-of-truth setup was a parking-lot item from PR #931 — under it, every reader had to trust the cache had been refreshed, and forgetting to refresh produced stale-value bugs.

Each reader now captures rows once at the top of its scope:
- persistColumnLayoutToStorage
- updateCache (the only true cache update; cachedRowCount/Count still derived)
- releaseData (just drops the now-removed field)
- DataGridView+CellPaste (anchor column count check)
- DataGridView+Sort (sortDescriptorsDidChange + menuNeedsUpdate header context menu)
- DataGridView+RowActions (undoInsertRow no longer needs the explicit refresh)

Net -6 LOC, one fewer field on the coordinator, and no possibility of cache/source drift.

Smoke-tested: column header context menu, click-to-sort, cell paste, undo-insert all behave as before.
@datlechin datlechin merged commit 39e1905 into main Apr 29, 2026
2 checks passed
@datlechin datlechin deleted the refactor/datagrid-collapse-cached-tablerows branch April 29, 2026 04:28
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: 5d6e954fed

ℹ️ 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 +32 to +33
let tableRows = tableRowsProvider()
guard !tableRows.columns.isEmpty else { return }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Persist column layout without depending on live row provider

Using tableRowsProvider() as the source of column names makes layout persistence fail during teardown paths where row data is removed before SwiftUI dismantles the grid. In performClose, removeTableRows(for:) runs before tabs are removed, so dismantleNSView can call persistColumnLayoutToStorage() after the provider already returns an empty TableRows; this new guard then exits early and skips saving widths/order for the current table. Previously the coordinator’s cached snapshot allowed persistence even after store teardown.

Useful? React with 👍 / 👎.

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