mirror of
https://github.com/ente-io/ente.git
synced 2025-08-08 07:28:26 +00:00
[mob][photos] Automatic sync
This commit is contained in:
parent
e414128f18
commit
e9392d8f33
@ -242,8 +242,13 @@ Future<void> _init(bool isBackground, {String via = ''}) async {
|
||||
// unawaited(ObjectDetectionService.instance.init());
|
||||
unawaited(FaceMlService.instance.init());
|
||||
FaceMlService.instance.listenIndexOnDiffSync();
|
||||
FaceMlService.instance.listenOnPeopleChangedSync();
|
||||
}
|
||||
PersonService.init(EntityService.instance, FaceMLDataDB.instance, preferences);
|
||||
PersonService.init(
|
||||
EntityService.instance,
|
||||
FaceMLDataDB.instance,
|
||||
preferences,
|
||||
);
|
||||
|
||||
_logger.info("Initialization done");
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import "package:photos/core/event_bus.dart";
|
||||
import "package:photos/db/files_db.dart";
|
||||
import "package:photos/events/diff_sync_complete_event.dart";
|
||||
import "package:photos/events/machine_learning_control_event.dart";
|
||||
import "package:photos/events/people_changed_event.dart";
|
||||
import "package:photos/extensions/list.dart";
|
||||
import "package:photos/extensions/stop_watch.dart";
|
||||
import "package:photos/face/db.dart";
|
||||
@ -39,6 +40,7 @@ import 'package:photos/services/machine_learning/face_ml/face_embedding/face_emb
|
||||
import 'package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.dart';
|
||||
import 'package:photos/services/machine_learning/face_ml/face_ml_exceptions.dart';
|
||||
import 'package:photos/services/machine_learning/face_ml/face_ml_result.dart';
|
||||
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
|
||||
import 'package:photos/services/machine_learning/file_ml/file_ml.dart';
|
||||
import 'package:photos/services/machine_learning/file_ml/remote_fileml_service.dart';
|
||||
import "package:photos/services/search_service.dart";
|
||||
@ -90,6 +92,7 @@ class FaceMlService {
|
||||
bool canRunMLController = false;
|
||||
bool isImageIndexRunning = false;
|
||||
bool isClusteringRunning = false;
|
||||
bool shouldSyncPeople = false;
|
||||
|
||||
final int _parallelismML = 10;
|
||||
final int _remoteFetchLimit = 100;
|
||||
@ -155,12 +158,19 @@ class FaceMlService {
|
||||
// [neeraj] intentional delay in starting indexing on diff sync, this gives time for the user
|
||||
// to disable face-indexing in case it's causing crash. In the future, we
|
||||
// should have a better way to handle this.
|
||||
shouldSyncPeople = true;
|
||||
Future.delayed(const Duration(seconds: 10), () {
|
||||
unawaited(indexAllImages());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void listenOnPeopleChangedSync() {
|
||||
Bus.instance.on<PeopleChangedEvent>().listen((event) {
|
||||
shouldSyncPeople = true;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> ensureInitialized() async {
|
||||
if (!isInitialized) {
|
||||
await init();
|
||||
@ -546,6 +556,11 @@ class FaceMlService {
|
||||
_logger.warning("indexAllImages is already running, skipping");
|
||||
return;
|
||||
}
|
||||
if (shouldSyncPeople) {
|
||||
await PersonService.instance.reconcileClusters();
|
||||
shouldSyncPeople = false;
|
||||
}
|
||||
|
||||
// verify faces is enabled
|
||||
if (LocalSettings.instance.isFaceIndexingEnabled == false) {
|
||||
_logger.warning("indexing is disabled by user");
|
||||
|
@ -298,7 +298,7 @@ class ClusterFeedbackService {
|
||||
|
||||
for (final suggestion in suggestions) {
|
||||
final clusterID = suggestion.$1;
|
||||
await PersonService.instance.assignClusterToPerson(
|
||||
await FaceMLDataDB.instance.assignClusterToPerson(
|
||||
personID: p.remoteID,
|
||||
clusterID: clusterID,
|
||||
);
|
||||
|
@ -1,4 +1,3 @@
|
||||
import "dart:async" show unawaited;
|
||||
import "dart:convert";
|
||||
import "dart:developer";
|
||||
|
||||
@ -183,32 +182,6 @@ class PersonService {
|
||||
return PersonEntity(result.id, data);
|
||||
}
|
||||
|
||||
Future<void> assignClusterToPerson({
|
||||
required String personID,
|
||||
required int clusterID,
|
||||
}) async {
|
||||
final person = (await getPerson(personID))!;
|
||||
final personData = person.data;
|
||||
final faceIds = await faceMLDataDB.getFaceIDsForCluster(clusterID);
|
||||
final clusterInfo = ClusterInfo(
|
||||
id: clusterID,
|
||||
faces: faceIds.toSet(),
|
||||
);
|
||||
personData.assigned!.add(clusterInfo);
|
||||
unawaited(
|
||||
entityService.addOrUpdate(
|
||||
EntityType.person,
|
||||
json.encode(personData.toJson()),
|
||||
id: personID,
|
||||
),
|
||||
);
|
||||
await faceMLDataDB.assignClusterToPerson(
|
||||
personID: personID,
|
||||
clusterID: clusterID,
|
||||
);
|
||||
personData.logStats();
|
||||
}
|
||||
|
||||
Future<void> removeClusterToPerson({
|
||||
required String personID,
|
||||
required int clusterID,
|
||||
|
@ -7,6 +7,7 @@ import "package:logging/logging.dart";
|
||||
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
|
||||
import "package:photos/core/event_bus.dart";
|
||||
import "package:photos/events/people_changed_event.dart";
|
||||
import "package:photos/face/db.dart";
|
||||
import "package:photos/face/model/person.dart";
|
||||
import "package:photos/generated/l10n.dart";
|
||||
import "package:photos/models/file/file.dart";
|
||||
@ -233,7 +234,7 @@ class _PersonActionSheetState extends State<PersonActionSheet> {
|
||||
return;
|
||||
}
|
||||
userAlreadyAssigned = true;
|
||||
await PersonService.instance.assignClusterToPerson(
|
||||
await FaceMLDataDB.instance.assignClusterToPerson(
|
||||
personID: person.$1.remoteID,
|
||||
clusterID: widget.cluserID,
|
||||
);
|
||||
|
@ -10,7 +10,6 @@ import "package:photos/face/db.dart";
|
||||
import "package:photos/face/model/person.dart";
|
||||
import "package:photos/models/file/file.dart";
|
||||
import 'package:photos/services/machine_learning/face_ml/feedback/cluster_feedback.dart';
|
||||
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
|
||||
import "package:photos/theme/ente_theme.dart";
|
||||
import "package:photos/ui/components/buttons/button_widget.dart";
|
||||
import "package:photos/ui/components/models/button_type.dart";
|
||||
@ -169,7 +168,7 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {
|
||||
}
|
||||
if (yesOrNo) {
|
||||
canGiveFeedback = false;
|
||||
await PersonService.instance.assignClusterToPerson(
|
||||
await FaceMLDataDB.instance.assignClusterToPerson(
|
||||
personID: widget.person.remoteID,
|
||||
clusterID: clusterID,
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user