mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
feat(mobile): hash assets in isolate (#18924)
This commit is contained in:
parent
b46e066cc2
commit
ce6631f7e0
34 changed files with 1254 additions and 428 deletions
|
|
@ -1,10 +1,13 @@
|
|||
// ignore_for_file: avoid-unsafe-collection-methods
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:immich_mobile/domain/models/store.model.dart';
|
||||
import 'package:immich_mobile/domain/utils/background_sync.dart';
|
||||
import 'package:immich_mobile/entities/album.entity.dart';
|
||||
import 'package:immich_mobile/entities/android_device_asset.entity.dart';
|
||||
import 'package:immich_mobile/entities/asset.entity.dart';
|
||||
|
|
@ -13,14 +16,16 @@ import 'package:immich_mobile/entities/ios_device_asset.entity.dart';
|
|||
import 'package:immich_mobile/entities/store.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/device_asset.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/exif.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/local_asset.entity.drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/store.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/user.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
|
||||
import 'package:immich_mobile/utils/diff.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
// ignore: import_rule_photo_manager
|
||||
import 'package:photo_manager/photo_manager.dart';
|
||||
|
||||
const int targetVersion = 11;
|
||||
const int targetVersion = 12;
|
||||
|
||||
Future<void> migrateDatabaseIfNeeded(Isar db) async {
|
||||
final int version = Store.get(StoreKey.version, targetVersion);
|
||||
|
|
@ -45,7 +50,15 @@ Future<void> migrateDatabaseIfNeeded(Isar db) async {
|
|||
await _migrateDeviceAsset(db);
|
||||
}
|
||||
|
||||
final shouldTruncate = version < 8 && version < targetVersion;
|
||||
if (version < 12 && (!kReleaseMode)) {
|
||||
final backgroundSync = BackgroundSyncManager();
|
||||
await backgroundSync.syncLocal();
|
||||
final drift = Drift();
|
||||
await _migrateDeviceAssetToSqlite(db, drift);
|
||||
await drift.close();
|
||||
}
|
||||
|
||||
final shouldTruncate = version < 8 || version < targetVersion;
|
||||
if (shouldTruncate) {
|
||||
await _migrateTo(db, targetVersion);
|
||||
}
|
||||
|
|
@ -154,6 +167,28 @@ Future<void> _migrateDeviceAsset(Isar db) async {
|
|||
});
|
||||
}
|
||||
|
||||
Future<void> _migrateDeviceAssetToSqlite(Isar db, Drift drift) async {
|
||||
final isarDeviceAssets =
|
||||
await db.deviceAssetEntitys.where().sortByAssetId().findAll();
|
||||
await drift.batch((batch) {
|
||||
for (final deviceAsset in isarDeviceAssets) {
|
||||
final companion = LocalAssetEntityCompanion(
|
||||
updatedAt: Value(deviceAsset.modifiedTime),
|
||||
id: Value(deviceAsset.assetId),
|
||||
checksum: Value(base64.encode(deviceAsset.hash)),
|
||||
);
|
||||
batch.insert<$LocalAssetEntityTable, LocalAssetEntityData>(
|
||||
drift.localAssetEntity,
|
||||
companion,
|
||||
onConflict: DoUpdate(
|
||||
(_) => companion,
|
||||
where: (old) => old.updatedAt.equals(deviceAsset.modifiedTime),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class _DeviceAsset {
|
||||
final String assetId;
|
||||
final List<int>? hash;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue