Skip to content

armgit / ente

Public Imported from GitHub
0

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

Split the type

Manav Rathi565546755a75
diff --git a/web/apps/photos/src/components/Search/SearchBar/searchInput/index.tsx b/web/apps/photos/src/components/Search/SearchBar/searchInput/index.tsx
index 9f493ba9c7..80a863b62e 100644
--- a/web/apps/photos/src/components/Search/SearchBar/searchInput/index.tsx
+++ b/web/apps/photos/src/components/Search/SearchBar/searchInput/index.tsx
@@ -1,6 +1,5 @@
import { FileType } from "@/media/file-type";
import { isMLEnabled } from "@/new/photos/services/ml";
-import type { Person } from "@/new/photos/services/ml/people";
import { EnteFile } from "@/new/photos/types/file";
import CloseIcon from "@mui/icons-material/Close";
import { IconButton } from "@mui/material";
@@ -19,6 +18,7 @@ import {
} from "services/searchService";
import { Collection } from "types/collection";
import { LocationTagData } from "types/entity";
+import type { SearchPerson } from "@/new/photos/services/search";
import {
ClipSearchScores,
DateValue,
@@ -146,7 +146,7 @@ export default function SearchInput(props: Iprops) {
search = { files: selectedOption.value as number[] };
break;
case SuggestionType.PERSON:
- search = { person: selectedOption.value as Person };
+ search = { person: selectedOption.value as SearchPerson };
break;
case SuggestionType.FILE_TYPE:
search = { fileType: selectedOption.value as FileType };
diff --git a/web/apps/photos/src/services/searchService.ts b/web/apps/photos/src/services/searchService.ts
index c469c4eec5..f9507bd675 100644
--- a/web/apps/photos/src/services/searchService.ts
+++ b/web/apps/photos/src/services/searchService.ts
@@ -9,7 +9,7 @@ import {
wipCluster,
wipClusterEnable,
} from "@/new/photos/services/ml";
-import type { Person } from "@/new/photos/services/ml/people";
+import type { SearchPerson } from "@/new/photos/services/search";
import { personDiff } from "@/new/photos/services/user-entity";
import { EnteFile } from "@/new/photos/types/file";
import * as chrono from "chrono-node";
@@ -406,7 +406,7 @@ function convertSuggestionToSearchQuery(option: Suggestion): Search {
return { files: option.value as number[] };
case SuggestionType.PERSON:
- return { person: option.value as Person };
+ return { person: option.value as SearchPerson };
case SuggestionType.FILE_TYPE:
return { fileType: option.value as FileType };
@@ -429,7 +429,7 @@ async function getAllPeople(limit: number = undefined) {
return [];
}
- let people: Array<Person> = []; // await mlIDbStorage.getAllPeople();
+ let people: Array<SearchPerson> = []; // await mlIDbStorage.getAllPeople();
people = await wipCluster();
// await mlPeopleStore.iterate<Person, void>((person) => {
// people.push(person);
diff --git a/web/apps/photos/src/types/search/index.ts b/web/apps/photos/src/types/search/index.ts
index fdb054f7f5..5c9158958a 100644
--- a/web/apps/photos/src/types/search/index.ts
+++ b/web/apps/photos/src/types/search/index.ts
@@ -1,6 +1,6 @@
import { FileType } from "@/media/file-type";
import type { MLStatus } from "@/new/photos/services/ml";
-import type { Person } from "@/new/photos/services/ml/people";
+import type { SearchPerson } from "@/new/photos/services/search";
import { EnteFile } from "@/new/photos/types/file";
import { City } from "services/locationSearchService";
import { LocationTagData } from "types/entity";
@@ -30,7 +30,7 @@ export interface Suggestion {
value:
| DateValue
| number[]
- | Person
+ | SearchPerson
| MLStatus
| LocationTagData
| City
@@ -45,7 +45,7 @@ export type Search = {
city?: City;
collection?: number;
files?: number[];
- person?: Person;
+ person?: SearchPerson;
fileType?: FileType;
clip?: ClipSearchScores;
};
diff --git a/web/packages/new/photos/components/PeopleList.tsx b/web/packages/new/photos/components/PeopleList.tsx
index adc53dbaf2..d3d6fe0c9c 100644
--- a/web/packages/new/photos/components/PeopleList.tsx
+++ b/web/packages/new/photos/components/PeopleList.tsx
@@ -1,14 +1,14 @@
import { faceCrop, unidentifiedFaceIDs } from "@/new/photos/services/ml";
-import type { Person } from "@/new/photos/services/ml/people";
import type { EnteFile } from "@/new/photos/types/file";
import { Skeleton, Typography, styled } from "@mui/material";
import { t } from "i18next";
import React, { useEffect, useState } from "react";
+import type { SearchPerson } from "../services/search";
export interface PeopleListProps {
- people: Person[];
+ people: SearchPerson[];
maxRows: number;
- onSelect?: (person: Person, index: number) => void;
+ onSelect?: (person: SearchPerson, index: number) => void;
}
export const PeopleList: React.FC<PeopleListProps> = ({
@@ -60,7 +60,7 @@ const FaceChip = styled("div")<{ clickable?: boolean }>`
export interface PhotoPeopleListProps {
file: EnteFile;
- onSelect?: (person: Person, index: number) => void;
+ onSelect?: (person: SearchPerson, index: number) => void;
}
export function PhotoPeopleList() {
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index 76ce68da36..5ca2bbe950 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -27,9 +27,9 @@ import {
faceIndexes,
indexableAndIndexedCounts,
} from "./db";
-import type { Person } from "./people";
import { MLWorker } from "./worker";
import type { CLIPMatches } from "./worker-types";
+import type { SearchPerson } from "../search";
/**
* Internal state of the ML subsystem.
@@ -314,7 +314,8 @@ export const indexNewUpload = (enteFile: EnteFile, uploadItem: UploadItem) => {
void worker().then((w) => w.onUpload(enteFile, uploadItem));
};
-let last: Person[] | undefined;
+// TODO-Cluster temporary import here
+let last: SearchPerson[] | undefined;
/**
* WIP! Don't enable, dragon eggs are hatching here.
@@ -335,7 +336,7 @@ export const wipCluster = async () => {
const localFiles = await getAllLocalFiles();
const localFilesByID = new Map(localFiles.map((f) => [f.id, f]));
- const people: Person[] = []; // await mlIDbStorage.getAllPeople();
+ const people: SearchPerson[] = []; // await mlIDbStorage.getAllPeople();
for (const cluster of clusters) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const dfID = cluster.faceIDs[0]!;
diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.ts
deleted file mode 100644
index d2d9c884a3..0000000000
--- a/web/packages/new/photos/services/ml/people.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import type { EnteFile } from "../../types/file";
-
-export interface Person {
- id: number;
- name?: string;
- files: number[];
- displayFaceID: string;
- displayFaceFile: EnteFile;
-}
-
-// Forced disable clustering. It doesn't currently work.
-//
-// > Error: Failed to execute 'transferToImageBitmap' on
-// > 'OffscreenCanvas': ImageBitmap construction failed
-
-/*
-export const syncPeopleIndex = async () => {
-
- if (
- syncContext.outOfSyncFiles.length <= 0 ||
- (syncContext.nSyncedFiles === batchSize && Math.random() < 0)
- ) {
- await this.syncIndex(syncContext);
- }
-
- public async syncIndex(syncContext: MLSyncContext) {
- await this.getMLLibraryData(syncContext);
-
- await syncPeopleIndex(syncContext);
-
- await this.persistMLLibraryData(syncContext);
- }
-
- const filesVersion = await mlIDbStorage.getIndexVersion("files");
- if (filesVersion <= (await mlIDbStorage.getIndexVersion("people"))) {
- return;
- }
-
-
-
- // await this.init();
-
- const allFacesMap = await mlIDbStorage.getAllFacesMap();
- const allFaces = [...allFacesMap.values()].flat();
-
- if (!allFaces || allFaces.length < 50) {
- log.info(
- `Skipping clustering since number of faces (${allFaces.length}) is less than the clustering threshold (50)`,
- );
- return;
- }
-
- log.info("Running clustering allFaces: ", allFaces.length);
- const faceClusteringResults = await clusterFaces(
- allFaces.map((f) => Array.from(f.embedding)),
- );
- log.info(
- "[MLService] Got face clustering results: ",
- JSON.stringify(faceClusteringResults),
- );
-
- const clusters = faceClusteringResults?.clusters;
- if (!clusters || clusters.length < 1) {
- return;
- }
-
- for (const face of allFaces) {
- face.personId = undefined;
- }
- await mlIDbStorage.clearAllPeople();
- for (const [index, cluster] of clusters.entries()) {
- const faces = cluster.map((f) => allFaces[f]).filter((f) => f);
-
-
- await mlIDbStorage.putPerson(person);
-
- faces.forEach((face) => {
- face.personId = person.id;
- });
-
- }
-
- await mlIDbStorage.updateFaces(allFacesMap);
-
- // await mlIDbStorage.setIndexVersion("people", filesVersion);
-};
-
-*/
diff --git a/web/packages/new/photos/services/search.ts b/web/packages/new/photos/services/search.ts
new file mode 100644
index 0000000000..300fad5c24
--- /dev/null
+++ b/web/packages/new/photos/services/search.ts
@@ -0,0 +1,13 @@
+import type { EnteFile } from "@/new/photos/types/file";
+
+/**
+ * A massaged version of {@link Person} suitable for being shown in search
+ * results.
+ */
+export interface SearchPerson {
+ id: number;
+ name?: string;
+ files: number[];
+ displayFaceID: string;
+ displayFaceFile: EnteFile;
+}