ย ยทย Data scientist, Taskraft.co.za

Speed up data import from a CSV/ XLSX

Good day everyone

I have a custom action importing an XLSX file documents to firebase via flutterflow. This action works but its speed is slow. Its taking 30 minutes to import a 6000 row document. Is there a recomended way to speed it up? I have been looking at rowy but I need the imports to be from the apps fromtend , Here is the custom Action. Thank you for your help in advance.๐Ÿ’Ÿ

Here is the custom Action code ๐Ÿ‘

// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:excel/excel.dart';
import 'dart:io';

// Set your action name, define your arguments and return parameter,
// and then add the boilerplate code using the button on the right!

Future<String> importXLSX(
    FFUploadedFile? uploadedFile, DocumentReference consignmentRef) async {
  String model = 'Model'; // Define voyageId outside the loop
  String vin = 'Vin';

  try {
    Uint8List? bytes = await uploadedFile!.bytes;
    var excel = Excel.decodeBytes(bytes!);

    if (bytes == null) {
      return 'Error 0'; // Error: Failed to get bytes
    }

    for (var table in excel.tables.keys) {
      for (var i = 1; i < excel.tables[table]!.maxRows; i++) {
        var row = excel.tables[table]!.row(i);

        if (row[0]?.value != null && row[1]?.value != null) {
          model = row[0]!.value.toString();
          vin = row[1]!.value.toString();

          // Create Firestore document in 'vehicles' collection with the 'scanned' field set to false
          DocumentReference<Map<String, dynamic>> documentReference =
              await FirebaseFirestore.instance.collection('vehicles').add({
            'model': model,
            'vin': vin,
            'consignment': consignmentRef,
            'scanned':
                false, // Add the 'scanned' field with a boolean value set to false
          });

          await consignmentRef.set({
            "vehicles": FieldValue.arrayUnion([documentReference]),
          }, SetOptions(merge: true));
        }
      }
    }
    return 'Successfully imported The Consignment Vehicles Excel File!';
  } catch (e) {
    print('Error: $e');
    return 'Error $e'; // Error
  }
}

1
7 replies