[mob] refactor

This commit is contained in:
Neeraj Gupta
2025-02-17 14:37:09 +05:30
parent 2a1f2aded1
commit fae23df6eb

View File

@@ -43,19 +43,14 @@ class RemoteDB {
Future<void> insertCollections(List<Collection> collections) async {
if (collections.isEmpty) return;
final stopwatch = Stopwatch()..start();
int inserted = 0;
await Future.forEach(collections.slices(_batchInsertMaxCount),
(slice) async {
debugPrint(
'$runtimeType insertCollections inserting slice of [${inserted + 1}, ${inserted + slice.length}] entries',
);
final List<List<Object?>> values =
slice.map((e) => e.rowValiues()).toList();
await _sqliteDB.executeBatch(
'INSERT OR REPLACE INTO collections ($collectionColumns) values($collectionValuePlaceHolder)',
values,
);
inserted += slice.length;
});
debugPrint(
'$runtimeType insertCollections complete in ${stopwatch.elapsed.inMilliseconds}ms for ${collections.length} collections',