From a3adba7232b1786aecfe050feff826fd5827b939 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Mon, 1 Jun 2026 22:27:15 +0700 Subject: [PATCH] perf(import): convert JSON array rows lazily to avoid a full duplicate row buffer (#1536) --- Plugins/JSONImportPlugin/JSONImportPlugin.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Plugins/JSONImportPlugin/JSONImportPlugin.swift b/Plugins/JSONImportPlugin/JSONImportPlugin.swift index 9bea84ff0..2f5be7019 100644 --- a/Plugins/JSONImportPlugin/JSONImportPlugin.swift +++ b/Plugins/JSONImportPlugin/JSONImportPlugin.swift @@ -70,10 +70,10 @@ final class JSONImportPlugin: ImportFormatPlugin, SettablePlugin { inserted: &inserted, skipped: &skipped, errors: &errors, maxErrors: maxErrors) } } else { - let rows = try Self.parseRows(at: url, targetTable: sink.targetTable) - for (index, row) in rows.enumerated() { + let rawRows = try Self.parseRows(at: url, targetTable: sink.targetTable) + for (index, rawRow) in rawRows.enumerated() { try progress.checkCancellation() - try await insert(row, into: sink, at: index + 1, progress: progress, + try await insert(Self.convertRow(rawRow), into: sink, at: index + 1, progress: progress, inserted: &inserted, skipped: &skipped, errors: &errors, maxErrors: maxErrors) } } @@ -145,10 +145,10 @@ final class JSONImportPlugin: ImportFormatPlugin, SettablePlugin { return convertRow(dict) } - static func parseRows(at url: URL, targetTable: String?) throws -> [[String: PluginCellValue]] { + static func parseRows(at url: URL, targetTable: String?) throws -> [[String: Any]] { let data = try Data(contentsOf: url) let object = try JSONSerialization.jsonObject(with: data) - return try extractRows(from: object, targetTable: targetTable).map(convertRow) + return try extractRows(from: object, targetTable: targetTable) } static func extractRows(from object: Any, targetTable: String?) throws -> [[String: Any]] {