[mob][photos] More refactor
This commit is contained in:
@@ -19,6 +19,7 @@ import "package:photos/ui/components/models/button_type.dart";
|
||||
import "package:photos/ui/viewer/people/cluster_page.dart";
|
||||
import "package:photos/ui/viewer/people/person_clusters_page.dart";
|
||||
import "package:photos/ui/viewer/search/result/person_face_widget.dart";
|
||||
import "package:photos/utils/face/face_box_crop.dart";
|
||||
|
||||
class SuggestionUserFeedback {
|
||||
final bool accepted;
|
||||
@@ -358,7 +359,7 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {
|
||||
final clusterID = suggestion.clusterIDToMerge;
|
||||
for (final file in files.sublist(0, min(files.length, 8))) {
|
||||
unawaited(
|
||||
PersonFaceWidget.precomputeNextFaceCrops(
|
||||
precomputeNextFaceCrops(
|
||||
file,
|
||||
clusterID,
|
||||
useFullFile: false,
|
||||
@@ -465,7 +466,7 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {
|
||||
final futures = <Future<Uint8List?>>[];
|
||||
for (final file in files) {
|
||||
futures.add(
|
||||
PersonFaceWidget.precomputeNextFaceCrops(
|
||||
precomputeNextFaceCrops(
|
||||
file,
|
||||
clusterID,
|
||||
useFullFile: false,
|
||||
|
||||
@@ -123,43 +123,4 @@ class PersonFaceWidget extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Uint8List?> precomputeNextFaceCrops(
|
||||
file,
|
||||
clusterID, {
|
||||
required bool useFullFile,
|
||||
}) async {
|
||||
try {
|
||||
final Face? face = await MLDataDB.instance.getCoverFaceForPerson(
|
||||
recentFileID: file.uploadedFileID!,
|
||||
clusterID: clusterID,
|
||||
);
|
||||
if (face == null) {
|
||||
debugPrint(
|
||||
"No cover face for cluster $clusterID and recentFile ${file.uploadedFileID}",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
EnteFile? fileForFaceCrop = file;
|
||||
if (face.fileID != file.uploadedFileID!) {
|
||||
fileForFaceCrop =
|
||||
await FilesDB.instance.getAnyUploadedFile(face.fileID);
|
||||
}
|
||||
if (fileForFaceCrop == null) {
|
||||
return null;
|
||||
}
|
||||
final cropMap = await getCachedFaceCrops(
|
||||
fileForFaceCrop,
|
||||
[face],
|
||||
useFullFile: useFullFile,
|
||||
);
|
||||
return cropMap?[face.faceID];
|
||||
} catch (e, s) {
|
||||
log(
|
||||
"Error getting cover face for cluster $clusterID",
|
||||
error: e,
|
||||
stackTrace: s,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import "dart:io" show File;
|
||||
import "package:flutter/foundation.dart";
|
||||
import "package:logging/logging.dart";
|
||||
import "package:photos/core/cache/lru_map.dart";
|
||||
import "package:photos/db/files_db.dart";
|
||||
import "package:photos/db/ml/db.dart";
|
||||
import "package:photos/models/file/file.dart";
|
||||
import "package:photos/models/file/file_type.dart";
|
||||
import "package:photos/models/ml/face/box.dart";
|
||||
@@ -126,6 +128,46 @@ Future<Map<String, Uint8List>?> getCachedFaceCrops(
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List?> precomputeNextFaceCrops(
|
||||
file,
|
||||
clusterID, {
|
||||
required bool useFullFile,
|
||||
}) async {
|
||||
try {
|
||||
final Face? face = await MLDataDB.instance.getCoverFaceForPerson(
|
||||
recentFileID: file.uploadedFileID!,
|
||||
clusterID: clusterID,
|
||||
);
|
||||
if (face == null) {
|
||||
debugPrint(
|
||||
"No cover face for cluster $clusterID and recentFile ${file.uploadedFileID}",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
EnteFile? fileForFaceCrop = file;
|
||||
if (face.fileID != file.uploadedFileID!) {
|
||||
fileForFaceCrop =
|
||||
await FilesDB.instance.getAnyUploadedFile(face.fileID);
|
||||
}
|
||||
if (fileForFaceCrop == null) {
|
||||
return null;
|
||||
}
|
||||
final cropMap = await getCachedFaceCrops(
|
||||
fileForFaceCrop,
|
||||
[face],
|
||||
useFullFile: useFullFile,
|
||||
);
|
||||
return cropMap?[face.faceID];
|
||||
} catch (e, s) {
|
||||
_logger.severe(
|
||||
"Error getting cover face for cluster $clusterID",
|
||||
e,
|
||||
s,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, Uint8List>?> _getFaceCrops(
|
||||
EnteFile file,
|
||||
Map<String, FaceBox> faceBoxeMap, {
|
||||
|
||||
Reference in New Issue
Block a user