This commit is contained in:
Manav Rathi 2024-05-16 14:37:02 +05:30
parent fca668b8e6
commit 23087ee8dc
No known key found for this signature in database
3 changed files with 25 additions and 34 deletions

View file

@ -1,6 +1,7 @@
import log from "@/next/log";
import mlIDbStorage from "services/face/db";
import { Face, MLSyncContext, Person } from "services/face/types";
import { Face, Person } from "services/face/types";
import { type MLSyncContext } from "services/machineLearning/machineLearningService";
import { clusterFaces } from "./cluster";
import { saveFaceCrop } from "./f-index";
import { fetchImageBitmap, getLocalFile } from "./image";

View file

@ -1,4 +1,3 @@
import PQueue from "p-queue";
import type { ClusterFacesResult } from "services/face/cluster";
import { Dimensions } from "services/face/geom";
import { EnteFile } from "types/file";
@ -140,27 +139,6 @@ export interface MLSearchConfig {
enabled: boolean;
}
export interface MLSyncContext {
token: string;
userID: number;
localFilesMap: Map<number, EnteFile>;
outOfSyncFiles: EnteFile[];
nSyncedFiles: number;
nSyncedFaces: number;
allSyncedFacesMap?: Map<number, Array<Face>>;
error?: Error;
// oldMLLibraryData: MLLibraryData;
mlLibraryData: MLLibraryData;
syncQueue: PQueue;
getEnteWorker(id: number): Promise<any>;
dispose(): Promise<void>;
}
export interface MLSyncFileContext {
enteFile: EnteFile;
localFile?: globalThis.File;

View file

@ -17,7 +17,6 @@ import {
Landmark,
MLLibraryData,
MLSearchConfig,
MLSyncContext,
MLSyncFileContext,
MLSyncResult,
MlFileData,
@ -59,6 +58,27 @@ export async function updateMLSearchConfig(newConfig: MLSearchConfig) {
return mlIDbStorage.putConfig(ML_SEARCH_CONFIG_NAME, newConfig);
}
export interface MLSyncContext {
token: string;
userID: number;
localFilesMap: Map<number, EnteFile>;
outOfSyncFiles: EnteFile[];
nSyncedFiles: number;
nSyncedFaces: number;
allSyncedFacesMap?: Map<number, Array<Face>>;
error?: Error;
// oldMLLibraryData: MLLibraryData;
mlLibraryData: MLLibraryData;
syncQueue: PQueue;
getEnteWorker(id: number): Promise<any>;
dispose(): Promise<void>;
}
export class LocalMLSyncContext implements MLSyncContext {
public token: string;
public userID: number;
@ -371,11 +391,7 @@ class MachineLearningService {
console.log(
`Indexing ${enteFile.title ?? "<untitled>"} ${enteFile.id}`,
);
const mlFileData = await this.syncFile(
syncContext,
enteFile,
localFile,
);
const mlFileData = await this.syncFile(enteFile, localFile);
syncContext.nSyncedFaces += mlFileData.faces?.length || 0;
syncContext.nSyncedFiles += 1;
return mlFileData;
@ -408,11 +424,7 @@ class MachineLearningService {
}
}
private async syncFile(
syncContext: MLSyncContext,
enteFile: EnteFile,
localFile?: globalThis.File,
) {
private async syncFile(enteFile: EnteFile, localFile?: globalThis.File) {
log.debug(() => ({ a: "Syncing file", enteFile }));
const fileContext: MLSyncFileContext = { enteFile, localFile };
const oldMlFile = await this.getMLFileData(enteFile.id);