Skip to content

Commit 2db4ee5

Browse files
committed
fix(concurrency): resolve Swift concurrency warnings
1 parent e061b29 commit 2db4ee5

4 files changed

Lines changed: 41 additions & 24 deletions

File tree

TablePro/Core/Services/SQL/SQLFolderWatcher.swift

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,17 @@ internal final class SQLFolderWatcher {
141141
return
142142
}
143143

144-
guard let enumerator = fileManager.enumerator(
145-
at: folderURL,
146-
includingPropertiesForKeys: [.isRegularFileKey, .contentModificationDateKey, .fileSizeKey],
147-
options: [.skipsHiddenFiles]
148-
) else {
149-
return
150-
}
151-
152144
var indexed: [LinkedSQLIndex.IndexedFile] = []
153145

154-
for case let url as URL in enumerator {
155-
guard SQLFileService.supportedExtensions.contains(url.pathExtension.lowercased()) else { continue }
156-
146+
enumerateSQLFileURLs(in: folderURL, fileManager: fileManager) { url in
157147
let resourceValues = try? url.resourceValues(forKeys: [
158148
.isRegularFileKey, .contentModificationDateKey, .fileSizeKey
159149
])
160-
guard resourceValues?.isRegularFile == true else { continue }
150+
guard resourceValues?.isRegularFile == true else { return }
161151
let mtime = resourceValues?.contentModificationDate ?? Date()
162152
let fileSize = Int64(resourceValues?.fileSize ?? 0)
163153

164-
guard let relativePath = relativePathFor(url: url, base: folderURL) else { continue }
154+
guard let relativePath = relativePathFor(url: url, base: folderURL) else { return }
165155
let header = FileTextLoader.loadHeader(url)
166156
let metadata = header.map { SQLFrontmatter.parse($0.content) } ?? SQLFrontmatter.Metadata()
167157
let encoding = header?.encoding ?? .utf8
@@ -184,6 +174,25 @@ internal final class SQLFolderWatcher {
184174
await LinkedSQLIndex.shared.replaceAll(folderId: folder.id, files: indexed, folderURL: folderURL)
185175
}
186176

177+
private static func enumerateSQLFileURLs(
178+
in folderURL: URL,
179+
fileManager: FileManager,
180+
handle: (URL) -> Void
181+
) {
182+
guard let enumerator = fileManager.enumerator(
183+
at: folderURL,
184+
includingPropertiesForKeys: [.isRegularFileKey, .contentModificationDateKey, .fileSizeKey],
185+
options: [.skipsHiddenFiles]
186+
) else {
187+
return
188+
}
189+
190+
for case let url as URL in enumerator {
191+
guard SQLFileService.supportedExtensions.contains(url.pathExtension.lowercased()) else { continue }
192+
handle(url)
193+
}
194+
}
195+
187196
private static func pruneRemovedFolders(stillKnownIds: Set<UUID>) async {
188197
let indexedIds = await LinkedSQLIndex.shared.allFolderIds()
189198
let stale = indexedIds.subtracting(stillKnownIds)

TablePro/ViewModels/WelcomeViewModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ final class WelcomeViewModel {
163163

164164
// MARK: - Initialization
165165

166-
init(services: AppServices = .live) {
166+
convenience init() {
167+
self.init(services: .live)
168+
}
169+
170+
init(services: AppServices) {
167171
self.services = services
168172
self.showOnboarding = !services.appSettingsStorage.hasCompletedOnboarding()
169173
}

TablePro/Views/Components/SQLReviewSheet.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ struct SQLReviewSheet: View {
3333
}
3434

3535
/// Past this many characters the display is truncated; the full text stays available via Copy All.
36-
static let maxDisplayChars = 20_000
36+
nonisolated static let maxDisplayChars = 20_000
3737
/// Past this many characters tree-sitter is skipped in favour of a plain monospaced view.
38-
static let treeSitterCutoff = 8_000
38+
nonisolated static let treeSitterCutoff = 8_000
3939

4040
var body: some View {
4141
VStack(spacing: 0) {
@@ -75,18 +75,23 @@ struct SQLReviewSheet: View {
7575

7676
private func prepare() async {
7777
guard prepared == nil, !statements.isEmpty else { return }
78-
let result = await Task.detached(priority: .userInitiated) { [statements, databaseType] in
79-
Self.build(statements: statements, databaseType: databaseType)
78+
let isJavaScript = PluginManager.shared.editorLanguage(for: databaseType) == .javascript
79+
let result = await Task.detached(priority: .userInitiated) { [statements, isJavaScript] in
80+
Self.build(statements: statements, isJavaScript: isJavaScript)
8081
}.value
8182
prepared = result
8283
}
8384

8485
static func build(statements: [String], databaseType: DatabaseType) -> Prepared {
85-
let isJS = PluginManager.shared.editorLanguage(for: databaseType) == .javascript
86+
let isJavaScript = PluginManager.shared.editorLanguage(for: databaseType) == .javascript
87+
return build(statements: statements, isJavaScript: isJavaScript)
88+
}
89+
90+
private nonisolated static func build(statements: [String], isJavaScript: Bool) -> Prepared {
8691
var full = statements
8792
.map { $0.hasSuffix(";") ? $0 : $0 + ";" }
8893
.joined(separator: "\n\n")
89-
if isJS {
94+
if isJavaScript {
9095
full = convertExtendedJsonToShellSyntax(full)
9196
}
9297

@@ -112,7 +117,7 @@ struct SQLReviewSheet: View {
112117
)
113118
}
114119

115-
static func convertExtendedJsonToShellSyntax(_ mql: String) -> String {
120+
nonisolated static func convertExtendedJsonToShellSyntax(_ mql: String) -> String {
116121
let pattern = #"\{"\$oid":\s*"([0-9a-fA-F]{24})"\}"#
117122
guard let regex = try? NSRegularExpression(pattern: pattern) else { return mql }
118123
let nsString = mql as NSString

TablePro/Views/Connection/ImportFromApp/ImportFromAppSourcePicker.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,10 @@ struct ImportFromAppSourcePicker: View {
164164
private func loadStates() {
165165
Task.detached(priority: .userInitiated) {
166166
let importers = ForeignAppImporterRegistry.all
167-
var states: [(importer: any ForeignAppImporter, available: Bool, count: Int)] = []
168-
for importer in importers {
167+
let states: [(importer: any ForeignAppImporter, available: Bool, count: Int)] = importers.map { importer in
169168
let available = importer.isAvailable()
170169
let count = available ? importer.connectionCount() : 0
171-
states.append((importer: importer, available: available, count: count))
170+
return (importer: importer, available: available, count: count)
172171
}
173172
await MainActor.run {
174173
importerStates = states

0 commit comments

Comments
 (0)