[mob] Insert collection_files
This commit is contained in:
@@ -6,6 +6,7 @@ import "package:flutter/foundation.dart";
|
||||
import "package:path/path.dart";
|
||||
import "package:path_provider/path_provider.dart";
|
||||
import "package:photos/db/remote/migration.dart";
|
||||
import "package:photos/models/api/diff/diff.dart";
|
||||
import "package:photos/models/collection/collection.dart";
|
||||
import "package:sqlite_async/sqlite_async.dart";
|
||||
|
||||
@@ -57,6 +58,52 @@ class RemoteDB {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> insertCollectionFilesDiff(
|
||||
List<CollectionFileItem> collections,
|
||||
) async {
|
||||
if (collections.isEmpty) return;
|
||||
final stopwatch = Stopwatch()..start();
|
||||
await Future.forEach(collections.slices(_batchInsertMaxCount),
|
||||
(slice) async {
|
||||
final List<List<Object?>> values = slice
|
||||
.map(
|
||||
(e) => [
|
||||
e.collectionID,
|
||||
e.fileID,
|
||||
e.encFileKey,
|
||||
e.encFileKeyNonce,
|
||||
e.createdAt,
|
||||
e.updatedAt,
|
||||
e.isDeleted ? 1 : 0,
|
||||
],
|
||||
)
|
||||
.toList();
|
||||
await _sqliteDB.executeBatch(
|
||||
'INSERT OR REPLACE INTO collection_files ($collectionFilesColumns) values(?, ?, ?, ?, ?, ?, ?)',
|
||||
values,
|
||||
);
|
||||
});
|
||||
debugPrint(
|
||||
'$runtimeType insertCollectionFilesDiff complete in ${stopwatch.elapsed.inMilliseconds}ms for ${collections.length}',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> deleteCollectionFilesDiff(
|
||||
List<CollectionFileItem> items,
|
||||
) async {
|
||||
if (items.isEmpty) return;
|
||||
final int collectionID = items.first.collectionID;
|
||||
final stopwatch = Stopwatch()..start();
|
||||
await Future.forEach(items.slices(_batchInsertMaxCount), (slice) async {
|
||||
await _sqliteDB.execute(
|
||||
'DELETE FROM collection_files WHERE file_id IN (${slice.map((e) => e.fileID).join(',')}) AND collection_id = $collectionID',
|
||||
);
|
||||
});
|
||||
debugPrint(
|
||||
'$runtimeType deleteCollectionFilesDiff complete in ${stopwatch.elapsed.inMilliseconds}ms for ${items.length}',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> deleteEntries<T>(Set<T> ids, RemoteTable table) async {
|
||||
if (ids.isEmpty) return;
|
||||
final stopwatch = Stopwatch()..start();
|
||||
|
||||
@@ -7,6 +7,8 @@ const collectionColumns =
|
||||
'mmd_ver, pub_mmd_encoded_json, pub_mmd_ver, shared_mmd_json, '
|
||||
'shared_mmd_ver';
|
||||
|
||||
const collectionFilesColumns =
|
||||
'collection_id, file_id, enc_key, enc_key_nonce, created_at, updated_at, is_deleted';
|
||||
String collectionValuePlaceHolder =
|
||||
collectionColumns.split(',').map((_) => '?').join(',');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user