rebase: convert string ids to byte uuids

This commit is contained in:
shenlong-tanwen 2025-03-29 12:01:19 +05:30
parent 3dc25406a7
commit 1fdb78b05d
4 changed files with 18 additions and 8 deletions

View File

@ -1,3 +1,7 @@
import 'dart:typed_data';
import 'package:uuid/parsing.dart';
extension StringExtension on String { extension StringExtension on String {
String capitalize() { String capitalize() {
return split(" ") return split(" ")
@ -29,3 +33,7 @@ extension DurationExtension on String {
return int.parse(this); return int.parse(this);
} }
} }
extension UUIDExtension on String {
Uint8List toUuidByte() => UuidParsing.parseAsByteList(this);
}

View File

@ -1,5 +1,6 @@
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
import 'package:immich_mobile/domain/interfaces/sync_stream.interface.dart'; import 'package:immich_mobile/domain/interfaces/sync_stream.interface.dart';
import 'package:immich_mobile/extensions/string_extensions.dart';
import 'package:immich_mobile/infrastructure/entities/partner.entity.drift.dart'; import 'package:immich_mobile/infrastructure/entities/partner.entity.drift.dart';
import 'package:immich_mobile/infrastructure/entities/user.entity.drift.dart'; import 'package:immich_mobile/infrastructure/entities/user.entity.drift.dart';
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart'; import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
@ -17,7 +18,7 @@ class DriftSyncStreamRepository extends DriftDatabaseRepository
Future<bool> deleteUsersV1(SyncUserDeleteV1 data) async { Future<bool> deleteUsersV1(SyncUserDeleteV1 data) async {
try { try {
await _db.managers.userEntity await _db.managers.userEntity
.filter((row) => row.id.equals(data.userId)) .filter((row) => row.id.equals(data.userId.toUuidByte()))
.delete(); .delete();
return true; return true;
} catch (e, s) { } catch (e, s) {
@ -35,7 +36,7 @@ class DriftSyncStreamRepository extends DriftDatabaseRepository
try { try {
await _db.userEntity.insertOne( await _db.userEntity.insertOne(
companion.copyWith(id: Value(data.id)), companion.copyWith(id: Value(data.id.toUuidByte())),
onConflict: DoUpdate((_) => companion), onConflict: DoUpdate((_) => companion),
); );
return true; return true;
@ -51,8 +52,8 @@ class DriftSyncStreamRepository extends DriftDatabaseRepository
await _db.managers.partnerEntity await _db.managers.partnerEntity
.filter( .filter(
(row) => (row) =>
row.sharedById.id.equals(data.sharedById) & row.sharedById.id.equals(data.sharedById.toUuidByte()) &
row.sharedWithId.id.equals(data.sharedWithId), row.sharedWithId.id.equals(data.sharedWithId.toUuidByte()),
) )
.delete(); .delete();
return true; return true;
@ -70,14 +71,14 @@ class DriftSyncStreamRepository extends DriftDatabaseRepository
try { try {
await _db.partnerEntity.insertOne( await _db.partnerEntity.insertOne(
companion.copyWith( companion.copyWith(
sharedById: Value(data.sharedById), sharedById: Value(data.sharedById.toUuidByte()),
sharedWithId: Value(data.sharedWithId), sharedWithId: Value(data.sharedWithId.toUuidByte()),
), ),
onConflict: DoUpdate((_) => companion), onConflict: DoUpdate((_) => companion),
); );
return true; return true;
} catch (e, s) { } catch (e, s) {
_logger.severe('Error while processing SyncUserV1', e, s); _logger.severe('Error while processing SyncPartnerV1', e, s);
return false; return false;
} }
} }

View File

@ -1798,7 +1798,7 @@ packages:
source: hosted source: hosted
version: "3.1.4" version: "3.1.4"
uuid: uuid:
dependency: transitive dependency: "direct main"
description: description:
name: uuid name: uuid
sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff

View File

@ -60,6 +60,7 @@ dependencies:
thumbhash: 0.1.0+1 thumbhash: 0.1.0+1
timezone: ^0.9.4 timezone: ^0.9.4
url_launcher: ^6.3.1 url_launcher: ^6.3.1
uuid: ^4.5.1
wakelock_plus: ^1.2.10 wakelock_plus: ^1.2.10
native_video_player: native_video_player: