|
@@ -128,7 +128,6 @@ extension DeviceFiles on FilesDB {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- // todo: covert it to batch
|
|
|
|
Future<void> insertLocalAssets(
|
|
Future<void> insertLocalAssets(
|
|
List<LocalPathAsset> localPathAssets, {
|
|
List<LocalPathAsset> localPathAssets, {
|
|
bool shouldAutoBackup = false,
|
|
bool shouldAutoBackup = false,
|
|
@@ -136,17 +135,18 @@ extension DeviceFiles on FilesDB {
|
|
final Database db = await database;
|
|
final Database db = await database;
|
|
final Map<String, Set<String>> pathIDToLocalIDsMap = {};
|
|
final Map<String, Set<String>> pathIDToLocalIDsMap = {};
|
|
try {
|
|
try {
|
|
|
|
+ final batch = db.batch();
|
|
final Set<String> existingPathIds = await getDevicePathIDs();
|
|
final Set<String> existingPathIds = await getDevicePathIDs();
|
|
for (LocalPathAsset localPathAsset in localPathAssets) {
|
|
for (LocalPathAsset localPathAsset in localPathAssets) {
|
|
pathIDToLocalIDsMap[localPathAsset.pathID] = localPathAsset.localIDs;
|
|
pathIDToLocalIDsMap[localPathAsset.pathID] = localPathAsset.localIDs;
|
|
if (existingPathIds.contains(localPathAsset.pathID)) {
|
|
if (existingPathIds.contains(localPathAsset.pathID)) {
|
|
- await db.rawUpdate(
|
|
|
|
|
|
+ batch.rawUpdate(
|
|
"UPDATE device_collections SET name = ? where id = "
|
|
"UPDATE device_collections SET name = ? where id = "
|
|
"?",
|
|
"?",
|
|
[localPathAsset.pathName, localPathAsset.pathID],
|
|
[localPathAsset.pathName, localPathAsset.pathID],
|
|
);
|
|
);
|
|
} else {
|
|
} else {
|
|
- await db.insert(
|
|
|
|
|
|
+ batch.insert(
|
|
"device_collections",
|
|
"device_collections",
|
|
{
|
|
{
|
|
"id": localPathAsset.pathID,
|
|
"id": localPathAsset.pathID,
|
|
@@ -157,6 +157,7 @@ extension DeviceFiles on FilesDB {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ await batch.commit(noResult: true);
|
|
// add the mappings for localIDs
|
|
// add the mappings for localIDs
|
|
if (pathIDToLocalIDsMap.isNotEmpty) {
|
|
if (pathIDToLocalIDsMap.isNotEmpty) {
|
|
await insertPathIDToLocalIDMapping(pathIDToLocalIDsMap);
|
|
await insertPathIDToLocalIDMapping(pathIDToLocalIDsMap);
|