Index new

This commit is contained in:
Manav Rathi
2024-07-04 15:12:28 +05:30
parent 41fe7ad794
commit 00de818e65
2 changed files with 14 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
import { FILE_TYPE } from "@/media/file-type";
import { potentialFileTypeFromExtension } from "@/media/live-photo";
import { getLocalFiles } from "@/new/photos/services/files";
import { onUpload as onUploadML } from "@/new/photos/services/ml";
import { indexNewlyUploadedFile } from "@/new/photos/services/ml";
import type { UploadItem } from "@/new/photos/services/upload/types";
import {
RANDOM_PERCENTAGE_PROGRESS_FOR_PUT,
@@ -635,7 +635,8 @@ class UploadManager {
enteFile: decryptedFile,
localFile: file,
});
onUploadML(decryptedFile, file);
if (UPLOAD_RESULT.UPLOADED == uploadResult)
indexNewlyUploadedFile(decryptedFile, file);
} catch (e) {
log.warn("Ignoring error in fileUploaded handlers", e);
}

View File

@@ -161,14 +161,23 @@ export const triggerMLSync = () => {
};
/**
* Called by the uploader when it uploads a new file from this client.
* Run indexing on a file which was uploaded from this client.
*
* This function is called by the uploader when it uploads a new file from this
* client, giving us the opportunity to index it live. This is only an
* optimization - if we don't index it now it'll anyways get indexed later as
* part of the batch jobs, but that might require downloading the file's
* contents again.
*
* @param enteFile The {@link EnteFile} that got uploaded.
*
* @param file When available, the web {@link File} object representing the
* contents of the file that got uploaded.
*/
export const onUpload = (enteFile: EnteFile, file: File | undefined) => {
export const indexNewlyUploadedFile = (
enteFile: EnteFile,
file: File | undefined,
) => {
if (!_isMLEnabled) return;
if (enteFile.metadata.fileType !== FILE_TYPE.IMAGE) return;
log.debug(() => ({ t: "ml-liveq", enteFile, file }));