Skip to content

Commit

Permalink
[mob] Misc bug fixes (#3522)
Browse files Browse the repository at this point in the history
## Description

## Tests
  • Loading branch information
ua741 authored Sep 29, 2024
2 parents d1d6590 + 00e75c0 commit fa36190
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
9 changes: 8 additions & 1 deletion mobile/lib/services/entity_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ class EntityService {
}
}

Future<void> syncEntity(EntityType type) async {
try {
await _remoteToLocalSync(type);
} catch (e) {
_logger.severe("Failed to sync entities", e);
}
}

Future<void> _remoteToLocalSync(EntityType type) async {
final int lastSyncTime =
_prefs.getInt(_getEntityLastSyncTimePrefix(type)) ?? 0;
Expand All @@ -116,7 +124,6 @@ class EntityService {
limit: fetchLimit,
);
if (result.isEmpty) {
debugPrint("No $type entries to sync");
return;
}
final bool hasMoreItems = result.length == fetchLimit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "package:logging/logging.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/diff_sync_complete_event.dart";
import "package:photos/events/people_changed_event.dart";
import "package:photos/models/api/entity/type.dart";
import "package:photos/services/entity_service.dart";
import "package:photos/services/machine_learning/face_ml/face_detection/detection.dart";
import "package:photos/services/machine_learning/face_ml/face_detection/face_detection_service.dart";
import "package:photos/services/machine_learning/face_ml/face_embedding/face_embedding_service.dart";
Expand Down Expand Up @@ -59,6 +61,7 @@ class FaceRecognitionService {
return;
}
_isSyncing = true;
await EntityService.instance.syncEntity(EntityType.cgroup);
if (_shouldSyncPeople) {
await PersonService.instance.reconcileClusters();
Bus.instance.fire(PeopleChangedEvent(type: PeopleEventType.syncDone));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class ClusterFeedbackService {
}

Future<void> ignoreCluster(String clusterID) async {
await PersonService.instance.addPerson('', clusterID);
await PersonService.instance.addPerson('', clusterID, isHidden: true);
Bus.instance.fire(PeopleChangedEvent());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import "package:photos/db/ml/db.dart";
import "package:photos/events/people_changed_event.dart";
import "package:photos/extensions/stop_watch.dart";
import "package:photos/models/api/entity/type.dart";
import "package:photos/models/file/file.dart";
import 'package:photos/models/ml/face/face.dart';
import "package:photos/models/ml/face/person.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/entity_service.dart";
Expand Down Expand Up @@ -292,6 +294,24 @@ class PersonService {
await faceMLDataDB.bulkAssignClusterToPersonID(clusterToPersonID);
}

Future<void> updateAvatar(PersonEntity p, EnteFile file) async {
final Face? face = await MLDataDB.instance.getCoverFaceForPerson(
recentFileID: file.uploadedFileID!,
personID: p.remoteID,
);
if (face == null) {
throw Exception(
"No face found for person ${p.remoteID} in file ${file.uploadedFileID}",
);
}

final person = (await getPerson(p.remoteID))!;
final updatedPerson = person.copyWith(
data: person.data.copyWith(avatarFaceId: face.faceID),
);
await _updatePerson(updatedPerson);
}

Future<void> updateAttributes(
String id, {
String? name,
Expand Down
8 changes: 1 addition & 7 deletions mobile/lib/services/remote_sync_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,7 @@ class RemoteSyncService {
await syncDeviceCollectionFilesForUpload();
}
await _pullDiff();
// sync trash but consume error during initial launch.
// this is to ensure that we don't pause upload due to any error during
// the trash sync. Impact: We may end up re-uploading a file which was
// recently trashed.
await TrashSyncService.instance
.syncTrash()
.onError((e, s) => _logger.severe('trash sync failed', e, s));
await TrashSyncService.instance.syncTrash();
if (!hasSyncedBefore) {
await _prefs.setBool(_isFirstRemoteSyncDone, true);
await syncDeviceCollectionFilesForUpload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,7 @@ class _FileSelectionActionsWidgetState

Future<void> _setPersonCover() async {
final EnteFile file = widget.selectedFiles.files.first;
await PersonService.instance.updateAttributes(
widget.person!.remoteID,
avatarFaceId: file.uploadedFileID.toString(),
);
await PersonService.instance.updateAvatar(widget.person!, file);
widget.selectedFiles.clearAll();
if (mounted) {
setState(() => {});
Expand Down
2 changes: 1 addition & 1 deletion mobile/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description: ente photos application
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

version: 0.9.45+945
version: 0.9.46+946
publish_to: none

environment:
Expand Down

0 comments on commit fa36190

Please sign in to comment.