Skip to content

Commit a3adba7

Browse files
committed
perf(import): convert JSON array rows lazily to avoid a full duplicate row buffer (#1536)
1 parent d1612f0 commit a3adba7

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Plugins/JSONImportPlugin/JSONImportPlugin.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ final class JSONImportPlugin: ImportFormatPlugin, SettablePlugin {
7070
inserted: &inserted, skipped: &skipped, errors: &errors, maxErrors: maxErrors)
7171
}
7272
} else {
73-
let rows = try Self.parseRows(at: url, targetTable: sink.targetTable)
74-
for (index, row) in rows.enumerated() {
73+
let rawRows = try Self.parseRows(at: url, targetTable: sink.targetTable)
74+
for (index, rawRow) in rawRows.enumerated() {
7575
try progress.checkCancellation()
76-
try await insert(row, into: sink, at: index + 1, progress: progress,
76+
try await insert(Self.convertRow(rawRow), into: sink, at: index + 1, progress: progress,
7777
inserted: &inserted, skipped: &skipped, errors: &errors, maxErrors: maxErrors)
7878
}
7979
}
@@ -145,10 +145,10 @@ final class JSONImportPlugin: ImportFormatPlugin, SettablePlugin {
145145
return convertRow(dict)
146146
}
147147

148-
static func parseRows(at url: URL, targetTable: String?) throws -> [[String: PluginCellValue]] {
148+
static func parseRows(at url: URL, targetTable: String?) throws -> [[String: Any]] {
149149
let data = try Data(contentsOf: url)
150150
let object = try JSONSerialization.jsonObject(with: data)
151-
return try extractRows(from: object, targetTable: targetTable).map(convertRow)
151+
return try extractRows(from: object, targetTable: targetTable)
152152
}
153153

154154
static func extractRows(from object: Any, targetTable: String?) throws -> [[String: Any]] {

0 commit comments

Comments
 (0)