private func saveTransactions(_ responses: [TransactionResponse], user: User) async -> Bool {
do {
return try await MainActor.run {
// Verify user is still current
guard currentUserId == user.id && currentCompanyId == userpanyID else {
print("⚠️ User changed during transaction save, aborting")
return false
}
// Insert transactions in batches of 100
let batchSize = 100
for batchStart in stride(from: 0, to: responses.count, by: batchSize) {
let batchEnd = min(batchStart + batchSize, responses.count)
let batch = responses[batchStart..<batchEnd]
// Insert batch
for response in batch {
let transaction = createTransaction(from: response, user: user)
modelContext.insert(transaction)
}
// Save after each batch
try modelContext.save()
print("