Skip to content

Commit 1d75264

Browse files
committed
fix: replace NSLog with os.Logger, use O(1) string length, fix localization
- SidebarViewModel: replace 5 NSLog calls with os.Logger (sidebarLogger) - CompletionTextField: string.count → (string as NSString).length for O(1) - TableProApp: Text("Preview \(name)") → String(format:) to fix localization key
1 parent e05c5e5 commit 1d75264

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

TablePro/TableProApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ struct AppMenuCommands: Commands {
218218
actions?.previewSQL()
219219
} label: {
220220
if let dbType = appState.currentDatabaseType {
221-
Text("Preview \(PluginManager.shared.queryLanguageName(for: dbType))")
221+
Text(String(format: String(localized: "Preview %@"), PluginManager.shared.queryLanguageName(for: dbType)))
222222
} else {
223223
Text("Preview SQL")
224224
}

TablePro/ViewModels/SidebarViewModel.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import Observation
10+
import os
1011
import SwiftUI
1112

1213
// MARK: - TableFetcher Protocol
@@ -16,6 +17,8 @@ protocol TableFetcher: Sendable {
1617
func fetchTables(force: Bool) async throws -> [TableInfo]
1718
}
1819

20+
private let sidebarLogger = Logger(subsystem: "com.TablePro", category: "SidebarViewModel")
21+
1922
/// Production implementation that uses DatabaseManager, with optional schema provider cache
2023
struct LiveTableFetcher: TableFetcher {
2124
let connectionId: UUID
@@ -36,12 +39,12 @@ struct LiveTableFetcher: TableFetcher {
3639
}
3740
}
3841
guard let driver = await DatabaseManager.shared.driver(for: connectionId) else {
39-
NSLog("[LiveTableFetcher] driver is nil for connectionId: %@", connectionId.uuidString)
42+
sidebarLogger.warning("Driver is nil for connection \(connectionId)")
4043
return []
4144
}
4245
let fetched = try await driver.fetchTables()
4346
.sorted { $0.name.localizedCaseInsensitiveCompare($1.name) == .orderedAscending }
44-
NSLog("[LiveTableFetcher] fetched %d tables", fetched.count)
47+
sidebarLogger.debug("Fetched \(fetched.count) tables")
4548
if let provider = schemaProvider {
4649
await provider.updateTables(fetched)
4750
}
@@ -155,14 +158,14 @@ final class SidebarViewModel {
155158

156159
func onAppear() {
157160
guard tables.isEmpty else {
158-
NSLog("[SidebarVM] onAppear: tables not empty (%d), skipping", tables.count)
161+
sidebarLogger.debug("onAppear: tables not empty (\(self.tables.count)), skipping")
159162
return
160163
}
161164
if DatabaseManager.shared.driver(for: connectionId) != nil {
162-
NSLog("[SidebarVM] onAppear: driver found, loading tables")
165+
sidebarLogger.debug("onAppear: loading tables")
163166
loadTables()
164167
} else {
165-
NSLog("[SidebarVM] onAppear: driver is nil for %@", connectionId.uuidString)
168+
sidebarLogger.warning("onAppear: driver is nil for \(self.connectionId)")
166169
}
167170
}
168171

TablePro/Views/Filter/CompletionTextField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct CompletionTextField: NSViewRepresentable {
9696
if commandSelector == #selector(NSResponder.insertNewlineIgnoringFieldEditor(_:)) {
9797
textView.insertNewlineIgnoringFieldEditor(nil)
9898
text.wrappedValue = textView.string
99-
previousTextLength = textView.string.count
99+
previousTextLength = (textView.string as NSString).length
100100
return true
101101
}
102102
return false

0 commit comments

Comments
 (0)