Skip to content

refactor(events): scope sqlFavoritesDidUpdate by connection id#1160

Merged
datlechin merged 1 commit into
mainfrom
refactor/sql-favorites-did-update-uuid-payload
May 9, 2026
Merged

refactor(events): scope sqlFavoritesDidUpdate by connection id#1160
datlechin merged 1 commit into
mainfrom
refactor/sql-favorites-did-update-uuid-payload

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

AppEvents.sqlFavoritesDidUpdate payload changes from PassthroughSubject<Void, Never> to PassthroughSubject<UUID?, Never>, matching the shape PR #1159 introduced for connectionUpdated. The per-connection subscribers now filter so editing a favorite for connection A no longer forces every other connection's cache and editor to refresh.

Senders updated (SQLFavoriteManager):

  • addFavorite / updateFavorite: send favorite.connectionId
  • addFolder / updateFolder: send folder.connectionId
  • deleteFavorite / deleteFavorites / deleteFolder: send nil (the connectionId isn't easily recoverable from the id-only delete API, and bulk delete may span connections)
  • postUpdateNotification gains a connectionId: UUID? parameter

Subscribers updated:

  • ConnectionDataCache (per-connection; refreshes its cached folders/favorites): filter payload == nil || payload == self.connectionId
  • SQLEditorView (per-connection; refreshes its keyword map): same filter

nil payloads still trigger refresh on every subscriber, preserving correctness for cross-connection favorites (favorite.connectionId == nil) and the delete paths that don't track connectionId.

Why this matters

Audit finding same-shape as X2 / R2. With three windows open against three different databases, editing one favorite previously caused the other two windows' caches and editors to refetch their entire favorite list and keyword map. After this PR they see the event but skip when the payload doesn't match.

The two other audit X items have been triaged but not fixed in this PR:

  • X3 (connectionStatusChanged): MainContentView already filters on connectionId. MainSplitViewController re-derives state from DatabaseManager.activeSessions rather than the event payload, so the missing filter is a small perf concern, not a correctness bug.
  • X4 (mainWindowWillClose): only fires when the last main window closes, so there is no "wrong coordinator" scenario today; adding a payload would be purely anticipatory.

Test plan

  • Open two windows against two different connections. In window 1, add/edit/delete a favorite scoped to connection A. Confirm window 2's editor and sidebar do not flicker / refetch (Console: search runRefresh or fetchKeywordMap).
  • Cross-connection favorite (no connectionId): confirm both windows refresh.
  • Bulk-delete favorites: confirm both windows refresh.
  • swiftlint --strict clean.

@datlechin datlechin merged commit 89b79ec into main May 9, 2026
2 checks passed
@datlechin datlechin deleted the refactor/sql-favorites-did-update-uuid-payload branch May 9, 2026 17:53
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