Skip to content

refactor: sidebar architecture - single source of truth, explicit loading states#690

Merged
datlechin merged 3 commits intomainfrom
refactor/sidebar-architecture
Apr 11, 2026
Merged

refactor: sidebar architecture - single source of truth, explicit loading states#690
datlechin merged 3 commits intomainfrom
refactor/sidebar-architecture

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

Summary

Complete architectural refactor of the sidebar table loading, database switching, and schema provider caching.

Before: 3 sources of truth for tables (session.tables, schema provider cache, LiveTableFetcher), race conditions during database switch, notification-based coupling, workaround flags (isSwitchingDatabase, Task.yield(), isRestoringSelection).

After: Single source of truth (session.tables), explicit SidebarLoadingState enum, coordinator-driven table fetching, no races.

What changed

  • SidebarLoadingState enum (.idle, .loading, .loaded, .error) replaces 3 implicit booleans (isLoading, isSwitchingDatabase, hasActiveConnection)
  • refreshTables() on coordinator replaces fire-and-forget reloadSidebar() Task
  • resetForDatabase() on SQLSchemaProvider replaces triple-call loadSchema() + invalidateTables() + invalidateCache()
  • Database switch is now a single linear pipeline: clear UI → driver switch → fetch → atomic update. No Task.yield(), no defer trap
  • SidebarViewModel stripped to pure presentation layer (batch ops, search, clipboard). Table fetching removed.
  • Notification decoupling: handleDatabaseDidConnect() no longer triggers reloadSidebar()

Removed (dead code / anti-patterns)

  • LiveTableFetcher struct and TableFetcher protocol
  • isRestoringSelection re-entrancy flag
  • onChange(of: tables) auto-reload from stale cache
  • invalidateCache(), invalidateTables(), fetchFreshTables() on SQLSchemaProvider
  • LiveTableFetcherTests.swift (194 lines)

Stats

  • 19 files changed, +132 -781 lines (649 net lines removed)
  • 1 test file deleted, 5 test files updated

Test plan

  • MySQL: switch databases, verify no table flash, correct tables load
  • PostgreSQL: switch databases (reconnects), verify no flash
  • Empty database: verify empty state shown (no infinite spinner)
  • Reconnect: disconnect/reconnect, verify tables reload
  • Autocomplete: verify suggestions work after database switch
  • AI chat: verify schema context after switch
  • Build succeeds with no warnings

@datlechin datlechin merged commit f415a9c into main Apr 11, 2026
2 checks passed
@datlechin datlechin deleted the refactor/sidebar-architecture branch April 11, 2026 18:47
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