You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-08-08 23:07:06 +02:00
refactor(mobile): remove int user id (#16814)
* refactor: user entity * chore: rebase fixes * refactor: remove int user Id * refactor: migrate store userId from int to string * refactor: rename uid to id * fix: migration * pr feedback --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
@ -11,6 +11,7 @@ import 'package:immich_mobile/infrastructure/entities/exif.entity.dart';
|
||||
import 'package:immich_mobile/interfaces/asset.interface.dart';
|
||||
import 'package:immich_mobile/providers/db.provider.dart';
|
||||
import 'package:immich_mobile/repositories/database.repository.dart';
|
||||
import 'package:immich_mobile/utils/hash.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
|
||||
final assetRepositoryProvider =
|
||||
@ -22,20 +23,21 @@ class AssetRepository extends DatabaseRepository implements IAssetRepository {
|
||||
@override
|
||||
Future<List<Asset>> getByAlbum(
|
||||
Album album, {
|
||||
Iterable<int> notOwnedBy = const [],
|
||||
int? ownerId,
|
||||
Iterable<String> notOwnedBy = const [],
|
||||
String? ownerId,
|
||||
AssetState? state,
|
||||
AssetSort? sortBy,
|
||||
}) {
|
||||
var query = album.assets.filter();
|
||||
final isarUserIds = notOwnedBy.map(fastHash).toList();
|
||||
if (notOwnedBy.length == 1) {
|
||||
query = query.not().ownerIdEqualTo(notOwnedBy.first);
|
||||
query = query.not().ownerIdEqualTo(isarUserIds.first);
|
||||
} else if (notOwnedBy.isNotEmpty) {
|
||||
query =
|
||||
query.not().anyOf(notOwnedBy, (q, int id) => q.ownerIdEqualTo(id));
|
||||
query.not().anyOf(isarUserIds, (q, int id) => q.ownerIdEqualTo(id));
|
||||
}
|
||||
if (ownerId != null) {
|
||||
query = query.ownerIdEqualTo(ownerId);
|
||||
query = query.ownerIdEqualTo(fastHash(ownerId));
|
||||
}
|
||||
|
||||
if (state != null) {
|
||||
@ -87,27 +89,28 @@ class AssetRepository extends DatabaseRepository implements IAssetRepository {
|
||||
|
||||
@override
|
||||
Future<List<Asset>> getAll({
|
||||
required int ownerId,
|
||||
required String ownerId,
|
||||
AssetState? state,
|
||||
AssetSort? sortBy,
|
||||
int? limit,
|
||||
}) {
|
||||
final baseQuery = db.assets.where();
|
||||
final isarUserIds = fastHash(ownerId);
|
||||
final QueryBuilder<Asset, Asset, QAfterFilterCondition> filteredQuery =
|
||||
switch (state) {
|
||||
null => baseQuery.ownerIdEqualToAnyChecksum(ownerId).noOp(),
|
||||
null => baseQuery.ownerIdEqualToAnyChecksum(isarUserIds).noOp(),
|
||||
AssetState.local => baseQuery
|
||||
.remoteIdIsNull()
|
||||
.filter()
|
||||
.localIdIsNotNull()
|
||||
.ownerIdEqualTo(ownerId),
|
||||
.ownerIdEqualTo(isarUserIds),
|
||||
AssetState.remote => baseQuery
|
||||
.localIdIsNull()
|
||||
.filter()
|
||||
.remoteIdIsNotNull()
|
||||
.ownerIdEqualTo(ownerId),
|
||||
.ownerIdEqualTo(isarUserIds),
|
||||
AssetState.merged => baseQuery
|
||||
.ownerIdEqualToAnyChecksum(ownerId)
|
||||
.ownerIdEqualToAnyChecksum(isarUserIds)
|
||||
.filter()
|
||||
.remoteIdIsNotNull()
|
||||
.localIdIsNotNull(),
|
||||
@ -132,7 +135,7 @@ class AssetRepository extends DatabaseRepository implements IAssetRepository {
|
||||
@override
|
||||
Future<List<Asset>> getMatches({
|
||||
required List<Asset> assets,
|
||||
required int ownerId,
|
||||
required String ownerId,
|
||||
AssetState? state,
|
||||
int limit = 100,
|
||||
}) {
|
||||
@ -147,7 +150,7 @@ class AssetRepository extends DatabaseRepository implements IAssetRepository {
|
||||
AssetState.merged =>
|
||||
baseQuery.localIdIsNotNull().filter().remoteIdIsNotNull(),
|
||||
};
|
||||
return _getMatchesImpl(query, ownerId, assets, limit);
|
||||
return _getMatchesImpl(query, fastHash(ownerId), assets, limit);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -185,10 +188,10 @@ class AssetRepository extends DatabaseRepository implements IAssetRepository {
|
||||
|
||||
@override
|
||||
Future<List<Asset?>> getAllByOwnerIdChecksum(
|
||||
List<int> ids,
|
||||
List<int> ownerIds,
|
||||
List<String> checksums,
|
||||
) =>
|
||||
db.assets.getAllByOwnerIdChecksum(ids, checksums);
|
||||
db.assets.getAllByOwnerIdChecksum(ownerIds, checksums);
|
||||
|
||||
@override
|
||||
Future<List<Asset>> getAllLocal() =>
|
||||
@ -224,30 +227,30 @@ class AssetRepository extends DatabaseRepository implements IAssetRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Asset>> getTrashAssets(int userId) {
|
||||
Future<List<Asset>> getTrashAssets(String userId) {
|
||||
return db.assets
|
||||
.where()
|
||||
.remoteIdIsNotNull()
|
||||
.filter()
|
||||
.ownerIdEqualTo(userId)
|
||||
.ownerIdEqualTo(fastHash(userId))
|
||||
.isTrashedEqualTo(true)
|
||||
.findAll();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Asset>> getRecentlyAddedAssets(int userId) {
|
||||
Future<List<Asset>> getRecentlyAddedAssets(String userId) {
|
||||
return db.assets
|
||||
.where()
|
||||
.ownerIdEqualToAnyChecksum(userId)
|
||||
.ownerIdEqualToAnyChecksum(fastHash(userId))
|
||||
.sortByFileCreatedAtDesc()
|
||||
.findAll();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Asset>> getMotionAssets(int userId) {
|
||||
Future<List<Asset>> getMotionAssets(String userId) {
|
||||
return db.assets
|
||||
.where()
|
||||
.ownerIdEqualToAnyChecksum(userId)
|
||||
.ownerIdEqualToAnyChecksum(fastHash(userId))
|
||||
.filter()
|
||||
.livePhotoVideoIdIsNotNull()
|
||||
.findAll();
|
||||
|
Reference in New Issue
Block a user