Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

refactor(photos):remove-unrequested-file-info-refactors

Aswin Asoka04222865191
diff --git a/web/packages/new/photos/components/PeopleList.tsx b/web/packages/new/photos/components/PeopleList.tsx
index 150e18e7cd..050d030241 100644
--- a/web/packages/new/photos/components/PeopleList.tsx
+++ b/web/packages/new/photos/components/PeopleList.tsx
@@ -133,63 +133,64 @@ export const FilePeopleList: React.FC<FilePeopleListProps> = ({
onAddPerson,
addPersonTitle,
addPersonLabel,
-}) => {
- const entries = [
- ...(manuallyAssignedPeople ?? [])
- .toSorted((a, b) => {
+}) => (
+ <FilePeopleList_>
+ {manuallyAssignedPeople
+ ?.toSorted((a, b) => {
const an = (a.name ?? "").toLowerCase();
const bn = (b.name ?? "").toLowerCase();
return an < bn ? -1 : an > bn ? 1 : 0;
})
- .map((person) => ({
- key: person.id,
- faceID: person.displayFaceID,
- file: person.displayFaceFile,
- name: person.name,
- isIgnored: person.type == "cgroup" && person.isHidden,
- onClick: () => onSelectPerson?.(person.id),
- })),
- ...annotatedFaceIDs.map((face) => ({
- key: face.faceID,
- faceID: face.faceID,
- file,
- name: face.personName,
- isIgnored: face.isIgnored,
- onClick: () => onSelectFace(face),
- })),
- ];
-
- return (
- <FilePeopleList_>
- {entries.map(({ key, faceID, file, name, isIgnored, onClick }) => (
- <AnnotatedFaceButton key={key} onClick={onClick}>
+ .map((person) => (
+ <ManuallyAssignedPersonButton
+ key={person.id}
+ onClick={() => onSelectPerson?.(person.id)}
+ >
<FaceCropImageView
- faceID={faceID}
- file={file}
+ faceID={person.displayFaceID}
+ file={person.displayFaceFile}
placeholderDimension={65}
/>
<Typography variant="small" sx={{ color: "text.muted" }}>
- {isIgnored ? `(${t("ignored")})` : name}
+ {person.type == "cgroup" && person.isHidden
+ ? `(${t("ignored")})`
+ : person.name}
</Typography>
- </AnnotatedFaceButton>
+ </ManuallyAssignedPersonButton>
))}
- {onAddPerson && (
- <AddPersonButton
- onClick={onAddPerson}
- title={addPersonTitle}
- aria-label={addPersonTitle}
- >
- <AddPersonAvatar>
- <PersonAddIcon />
- </AddPersonAvatar>
- <Typography variant="small" sx={{ color: "text.muted" }}>
- {addPersonLabel}
- </Typography>
- </AddPersonButton>
- )}
- </FilePeopleList_>
- );
-};
+ {annotatedFaceIDs.map((annotatedFaceID) => (
+ <AnnotatedFaceButton
+ key={annotatedFaceID.faceID}
+ onClick={() => onSelectFace(annotatedFaceID)}
+ >
+ <FaceCropImageView
+ faceID={annotatedFaceID.faceID}
+ file={file}
+ placeholderDimension={65}
+ />
+ <Typography variant="small" sx={{ color: "text.muted" }}>
+ {annotatedFaceID.isIgnored
+ ? `(${t("ignored")})`
+ : annotatedFaceID.personName}
+ </Typography>
+ </AnnotatedFaceButton>
+ ))}
+ {onAddPerson && (
+ <AddPersonButton
+ onClick={onAddPerson}
+ title={addPersonTitle}
+ aria-label={addPersonTitle}
+ >
+ <AddPersonAvatar>
+ <PersonAddIcon />
+ </AddPersonAvatar>
+ <Typography variant="small" sx={{ color: "text.muted" }}>
+ {addPersonLabel}
+ </Typography>
+ </AddPersonButton>
+ )}
+ </FilePeopleList_>
+);
const FilePeopleList_ = styled("div")`
display: flex;
@@ -217,6 +218,8 @@ const AnnotatedFaceButton = styled(UnstyledButton)(
`,
);
+const ManuallyAssignedPersonButton = AnnotatedFaceButton;
+
const AddPersonButton = styled(UnstyledButton)(
({ theme }) => `
width: 65px;
diff --git a/web/packages/new/photos/services/ml/face.ts b/web/packages/new/photos/services/ml/face.ts
index 7fe4bff9ff..a6d8501e1f 100644
--- a/web/packages/new/photos/services/ml/face.ts
+++ b/web/packages/new/photos/services/ml/face.ts
@@ -1,42 +1,4 @@
import { assertionFailed } from "ente-base/assert";
-import type { Person } from "./people";
-
-export interface AnnotatedFaceID {
- faceID: string;
- personID: string;
- personName: string | undefined;
- isIgnored: boolean;
-}
-
-export const annotateFileFaces = (
- faces: Face[],
- personByFaceID: ReadonlyMap<string, Person>,
-): AnnotatedFaceID[] => {
- const annotatedFaces = faces.flatMap(({ faceID, score }) => {
- const person = personByFaceID.get(faceID);
- if (!person) return [];
- return [
- {
- annotation: {
- faceID,
- personID: person.id,
- personName: person.name,
- isIgnored: person.type == "cgroup" && person.isHidden,
- },
- isAssigned: person.type == "cgroup",
- score,
- },
- ];
- });
-
- annotatedFaces.sort((a, b) => {
- if (a.annotation.isIgnored != b.annotation.isIgnored)
- return a.annotation.isIgnored ? 1 : -1;
- if (a.isAssigned != b.isAssigned) return a.isAssigned ? -1 : 1;
- return b.score - a.score;
- });
- return annotatedFaces.map(({ annotation }) => annotation);
-};
export const faceIndexingVersion = 1;
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index 0a62456c0f..0e283deec1 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -25,11 +25,7 @@ import { deleteUserEntity } from "../user-entity/remote";
import type { ClusterFacesReason, FaceCluster } from "./cluster";
import { regenerateFaceCrops } from "./crop";
import { clearMLDB, savedFaceIndex, savedIndexCounts } from "./db";
-import {
- annotateFileFaces,
- fileIDFromFaceID,
- type AnnotatedFaceID,
-} from "./face";
+import { fileIDFromFaceID } from "./face";
import {
_applyPersonSuggestionUpdates,
filterNamedPeople,
@@ -337,7 +333,12 @@ export const clipMatches = (
): Promise<CLIPMatches | undefined> =>
worker().then((w) => w.clipMatches(searchPhrase));
-export type { AnnotatedFaceID } from "./face";
+export interface AnnotatedFaceID {
+ faceID: string;
+ personID: string;
+ personName: string | undefined;
+ isIgnored: boolean;
+}
export const getAnnotatedFacesForFile = async (
file: EnteFile,
@@ -350,7 +351,28 @@ export const getAnnotatedFacesForFile = async (
const personByFaceID = _state.peopleStateSnapshot?.personByFaceID;
if (!personByFaceID) return [];
- return annotateFileFaces(index.faces, personByFaceID);
+ const sortableFaces: [AnnotatedFaceID, number, boolean][] = [];
+ for (const { faceID, score } of index.faces) {
+ const person = personByFaceID.get(faceID);
+ if (!person) continue;
+ sortableFaces.push([
+ {
+ faceID,
+ personID: person.id,
+ personName: person.name,
+ isIgnored: person.type == "cgroup" && person.isHidden,
+ },
+ score,
+ person.type == "cgroup",
+ ]);
+ }
+
+ sortableFaces.sort((a, b) => {
+ if (a[0].isIgnored != b[0].isIgnored) return a[0].isIgnored ? 1 : -1;
+ if (a[2] != b[2]) return a[2] ? -1 : 1;
+ return b[1] - a[1];
+ });
+ return sortableFaces.map(([f]) => f);
};
export const faceCrop = async (faceID: string, file: EnteFile) => {