Add models for upload mapping
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import "package:photos/models/api/diff/diff.dart";
|
||||
import "package:photos/models/file/remote/asset.dart";
|
||||
import "package:photos/models/file/remote/rl_mapping.dart";
|
||||
|
||||
RemoteAsset fromRow(Map<String, dynamic> row) {
|
||||
final metadata = Metadata.fromEncodedJson(row['metadata']);
|
||||
@@ -17,3 +18,13 @@ RemoteAsset fromRow(Map<String, dynamic> row) {
|
||||
info: info,
|
||||
);
|
||||
}
|
||||
|
||||
RLMapping rowToUploadLocalMapping(Map<String, Object?> row) {
|
||||
return RLMapping(
|
||||
remoteUploadID: row['file_id'] as int,
|
||||
localID: row['local_id'] as String,
|
||||
localCloudID: row['local_clould_id'] as String?,
|
||||
mappingType:
|
||||
MappingTypeExtension.fromName(row['local_mapping_src'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -29,17 +29,15 @@ const filesColumns =
|
||||
|
||||
final String filesUpdateColumns = filesColumns
|
||||
.split(', ')
|
||||
.where(
|
||||
(column) => (column != 'id' ||
|
||||
column != 'local_id' ||
|
||||
column != 'local_mapping_src'),
|
||||
) // Exclude primary key from update
|
||||
.where((column) => (column != 'id'))
|
||||
.map((column) => '$column = excluded.$column') // Use excluded virtual table
|
||||
.join(', ');
|
||||
|
||||
const trashedFilesColumns =
|
||||
'id, owner_id, file_header, thumb_header, metadata, priv_metadata, pub_metadata, info, trash_data';
|
||||
|
||||
const uploadLocalMappingColumns =
|
||||
'file_id, local_id, local_clould_id, local_mapping_src';
|
||||
String collectionValuePlaceHolder =
|
||||
collectionColumns.split(',').map((_) => '?').join(',');
|
||||
|
||||
|
||||
32
mobile/lib/db/remote/table/mapping_table.dart
Normal file
32
mobile/lib/db/remote/table/mapping_table.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import "package:collection/collection.dart";
|
||||
import "package:flutter/foundation.dart";
|
||||
import "package:photos/db/remote/db.dart";
|
||||
import "package:photos/db/remote/mappers.dart";
|
||||
import "package:photos/db/remote/schema.dart";
|
||||
import "package:photos/models/file/remote/rl_mapping.dart";
|
||||
|
||||
extension UploadMappingTable on RemoteDB {
|
||||
Future<void> insertMappings(List<RLMapping> mappings) async {
|
||||
if (mappings.isEmpty) return;
|
||||
final stopwatch = Stopwatch()..start();
|
||||
await Future.forEach(mappings.slices(1000), (slice) async {
|
||||
final List<List<Object?>> values = slice.map((e) => e.rowValues).toList();
|
||||
await sqliteDB.executeBatch(
|
||||
'INSERT INTO upload_mapping ($uploadLocalMappingColumns) values(?,?,?,?)',
|
||||
values,
|
||||
);
|
||||
});
|
||||
debugPrint(
|
||||
'$runtimeType insertMappings complete in ${stopwatch.elapsed.inMilliseconds}ms for ${mappings.length} mappings',
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<RLMapping>> getMappings() async {
|
||||
final result = <RLMapping>[];
|
||||
final cursor = await sqliteDB.getAll("SELECT * FROM upload_mapping");
|
||||
for (final row in cursor) {
|
||||
result.add(rowToUploadLocalMapping(row));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,57 @@
|
||||
enum MappingType {
|
||||
class RLMapping {
|
||||
final int remoteUploadID;
|
||||
final String localID;
|
||||
final String? localCloudID;
|
||||
final MatchType mappingType;
|
||||
|
||||
RLMapping({
|
||||
required this.remoteUploadID,
|
||||
required this.localID,
|
||||
required this.localCloudID,
|
||||
required this.mappingType,
|
||||
});
|
||||
|
||||
List<Object?> get rowValues => [
|
||||
remoteUploadID,
|
||||
localID,
|
||||
localCloudID,
|
||||
mappingType,
|
||||
];
|
||||
}
|
||||
|
||||
enum MatchType {
|
||||
remote,
|
||||
cloudIdMatched,
|
||||
deviceUpload,
|
||||
deviceHashMatched,
|
||||
}
|
||||
|
||||
extension MappingTypeExtension on MappingType {
|
||||
extension MappingTypeExtension on MatchType {
|
||||
String get name {
|
||||
switch (this) {
|
||||
case MappingType.remote:
|
||||
case MatchType.remote:
|
||||
return "remote";
|
||||
case MappingType.cloudIdMatched:
|
||||
case MatchType.cloudIdMatched:
|
||||
return "cloudIdMatched";
|
||||
case MappingType.deviceUpload:
|
||||
case MatchType.deviceUpload:
|
||||
return "deviceUpload";
|
||||
case MappingType.deviceHashMatched:
|
||||
case MatchType.deviceHashMatched:
|
||||
return "deviceHashMatched";
|
||||
}
|
||||
}
|
||||
|
||||
MappingType fromName(String name) {
|
||||
static MatchType fromName(String name) {
|
||||
switch (name) {
|
||||
case "remote":
|
||||
return MappingType.remote;
|
||||
return MatchType.remote;
|
||||
case "cloudIdMatched":
|
||||
return MappingType.cloudIdMatched;
|
||||
return MatchType.cloudIdMatched;
|
||||
case "deviceUpload":
|
||||
return MappingType.deviceUpload;
|
||||
return MatchType.deviceUpload;
|
||||
case "deviceHashMatched":
|
||||
return MappingType.deviceHashMatched;
|
||||
return MatchType.deviceHashMatched;
|
||||
default:
|
||||
throw Exception("Unknown mapping type: $name");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UploadLocalMapping {
|
||||
final int remoteUploadID;
|
||||
final String localID;
|
||||
final String? localCloudID;
|
||||
final MappingType mappingType;
|
||||
|
||||
UploadLocalMapping({
|
||||
required this.remoteUploadID,
|
||||
required this.localID,
|
||||
required this.localCloudID,
|
||||
required this.mappingType,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user