Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions TablePro/Core/Storage/ConnectionStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,22 @@ final class ConnectionStorage {

/// Save all connections
func saveConnections(_ connections: [DatabaseConnection]) {
cachedConnections = connections

let storedConnections = connections.map { StoredConnection(from: $0) }

do {
let data = try encoder.encode(storedConnections)
defaults.set(data, forKey: connectionsKey)
cachedConnections = nil
} catch {
Self.logger.error("Failed to save connections: \(error)")
}
}

/// Invalidate the in-memory cache so the next load reads fresh from UserDefaults.
func invalidateCache() {
cachedConnections = nil
}

/// Add a new connection
func addConnection(_ connection: DatabaseConnection, password: String? = nil) {
var connections = loadConnections()
Expand Down
3 changes: 3 additions & 0 deletions TablePro/Core/Sync/SyncCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ final class SyncCoordinator {
private func applyRemoteChanges(_ result: PullResult) {
let settings = AppSettingsStorage.shared.loadSync()

// Invalidate caches before applying remote data to ensure fresh reads
ConnectionStorage.shared.invalidateCache()

// Suppress change tracking during remote apply to avoid sync loops
changeTracker.isSuppressed = true
defer {
Expand Down
Loading