|
|
@@ -1292,9 +1292,7 @@ processCsvData(File tempfile, SupabaseClient supabase) async {
|
|
|
filename: filename, data: utf8.decode(await tempfile.readAsBytes())));
|
|
|
}
|
|
|
|
|
|
- while (csvData.isNotEmpty) {
|
|
|
- final data = csvData.first;
|
|
|
- csvData.removeAt(0);
|
|
|
+ for (final FilesAsData data in csvData) {
|
|
|
print(" processing ${data.filename}");
|
|
|
//inserting data
|
|
|
if (tables.keys.contains(data.filename)) {
|
|
|
@@ -1306,21 +1304,23 @@ processCsvData(File tempfile, SupabaseClient supabase) async {
|
|
|
.fold(<String>{}, (t, e) => t..add(e[scopeName] ?? "")).toList();
|
|
|
|
|
|
// print("Loading old data scope: ${scopeInNew.length}");
|
|
|
- List<Map<String, dynamic>> old = [];
|
|
|
+ List<Map<String, dynamic>> oldIds = [];
|
|
|
+ List<Map<String, dynamic>> oldComparable = [];
|
|
|
+
|
|
|
for (var e in splitList(scopeInNew, headerToNb(scopeInNew))) {
|
|
|
final res = await supabase
|
|
|
.from(tables[data.filename]!)
|
|
|
.select()
|
|
|
.inFilter(scopeName, e)
|
|
|
.limit(100000);
|
|
|
- old.addAll(res);
|
|
|
+ oldIds.addAll(res.map((e) => filterMapByKeys(e, ["id"])).toList());
|
|
|
+ oldComparable.addAll(res
|
|
|
+ .map((e) => filterMapByKeys(e, headers[data.filename] ?? []))
|
|
|
+ .toList());
|
|
|
// print("Loaded old data scope: ${e.length}");
|
|
|
}
|
|
|
|
|
|
// Replace with your actual table name
|
|
|
- final oldComparable = old
|
|
|
- .map((e) => filterMapByKeys(e, headers[data.filename] ?? []))
|
|
|
- .toList();
|
|
|
|
|
|
List<int> indexToRemove = [];
|
|
|
List<int> indexToMaintain = [];
|
|
|
@@ -1348,8 +1348,9 @@ processCsvData(File tempfile, SupabaseClient supabase) async {
|
|
|
}
|
|
|
|
|
|
//removing index to remove with id
|
|
|
- for (var e in splitList(indexToRemove.map((e) => old[e]['id']).toList(),
|
|
|
- headerToNb(indexToRemove.map((e) => old[e]['id']).toList()))) {
|
|
|
+ for (var e in splitList(
|
|
|
+ indexToRemove.map((e) => oldIds[e]['id']).toList(),
|
|
|
+ headerToNb(indexToRemove.map((e) => oldIds[e]['id']).toList()))) {
|
|
|
await supabase
|
|
|
.from(tables[data.filename]!) // Replace with your actual table name
|
|
|
.delete()
|