Forward the upload item
This commit is contained in:
@@ -614,11 +614,11 @@ class UploadManager {
|
||||
UPLOAD_RESULT.UPLOADED_WITH_STATIC_THUMBNAIL,
|
||||
].includes(uploadResult)
|
||||
) {
|
||||
const uploadItem =
|
||||
uploadableItem.uploadItem ??
|
||||
uploadableItem.livePhotoAssets.image;
|
||||
try {
|
||||
let file: File | undefined;
|
||||
const uploadItem =
|
||||
uploadableItem.uploadItem ??
|
||||
uploadableItem.livePhotoAssets.image;
|
||||
if (uploadItem) {
|
||||
if (uploadItem instanceof File) {
|
||||
file = uploadItem;
|
||||
@@ -635,15 +635,17 @@ class UploadManager {
|
||||
enteFile: decryptedFile,
|
||||
localFile: file,
|
||||
});
|
||||
if (
|
||||
uploadResult == UPLOAD_RESULT.UPLOADED ||
|
||||
uploadResult ==
|
||||
UPLOAD_RESULT.UPLOADED_WITH_STATIC_THUMBNAIL
|
||||
)
|
||||
indexNewUpload(decryptedFile, file);
|
||||
} catch (e) {
|
||||
log.warn("Ignoring error in fileUploaded handlers", e);
|
||||
}
|
||||
if (
|
||||
uploadItem &&
|
||||
(uploadResult == UPLOAD_RESULT.UPLOADED ||
|
||||
uploadResult ==
|
||||
UPLOAD_RESULT.UPLOADED_WITH_STATIC_THUMBNAIL)
|
||||
) {
|
||||
indexNewUpload(decryptedFile, uploadItem);
|
||||
}
|
||||
this.updateExistingFiles(decryptedFile);
|
||||
}
|
||||
await this.watchFolderCallback(
|
||||
|
||||
@@ -13,6 +13,7 @@ import { blobCache } from "@/next/blob-cache";
|
||||
import { ensureElectron } from "@/next/electron";
|
||||
import log from "@/next/log";
|
||||
import { ComlinkWorker } from "@/next/worker/comlink-worker";
|
||||
import type { UploadItem } from "../upload/types";
|
||||
import { regenerateFaceCrops } from "./crop";
|
||||
import { clearFaceDB, faceIndex, indexableAndIndexedCounts } from "./db";
|
||||
import { MLWorker } from "./worker";
|
||||
@@ -171,16 +172,14 @@ export const triggerMLSync = () => {
|
||||
*
|
||||
* @param enteFile The {@link EnteFile} that got uploaded.
|
||||
*
|
||||
* @param file When available, the web {@link File} object representing the
|
||||
* @param uploadItem The item that was uploaded. This can be used to get at the
|
||||
* contents of the file that got uploaded.
|
||||
*/
|
||||
export const indexNewUpload = (enteFile: EnteFile, file: File | undefined) => {
|
||||
export const indexNewUpload = (enteFile: EnteFile, uploadItem: UploadItem) => {
|
||||
if (!_isMLEnabled) return;
|
||||
if (enteFile.metadata.fileType !== FILE_TYPE.IMAGE) return;
|
||||
log.debug(() => ({ t: "ml-liveq", enteFile, file }));
|
||||
// TODO-ML: 1. Use this file!
|
||||
// TODO-ML: 2. Handle cases when File is something else (e.g. on desktop).
|
||||
void worker().then((w) => w.onUpload(enteFile));
|
||||
log.debug(() => ({ t: "ml-liveq", enteFile, uploadItem }));
|
||||
void worker().then((w) => w.onUpload(enteFile, uploadItem));
|
||||
};
|
||||
|
||||
export interface FaceIndexingStatus {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { wait } from "@/utils/promise";
|
||||
import { expose } from "comlink";
|
||||
import downloadManager from "../download";
|
||||
import { getAllLocalFiles, getLocalTrashedFiles } from "../files";
|
||||
import type { UploadItem } from "../upload/types";
|
||||
import {
|
||||
indexableFileIDs,
|
||||
markIndexingFailed,
|
||||
@@ -45,7 +46,7 @@ const idleDurationMax = 16 * 60; /* 16 minutes */
|
||||
export class MLWorker {
|
||||
private userAgent: string | undefined;
|
||||
private shouldSync = false;
|
||||
private liveQ: EnteFile[] = [];
|
||||
private liveQ: { enteFile: EnteFile; uploadItem: UploadItem }[] = [];
|
||||
private state: "idle" | "pull" | "indexing" = "idle";
|
||||
private idleTimeout: ReturnType<typeof setTimeout> | undefined;
|
||||
private idleDuration = idleDurationStart; /* unit: seconds */
|
||||
@@ -101,7 +102,7 @@ export class MLWorker {
|
||||
* representation of the file's contents with us and won't need to download
|
||||
* the file from remote.
|
||||
*/
|
||||
onUpload(file: EnteFile) {
|
||||
onUpload(enteFile: EnteFile, uploadItem: UploadItem) {
|
||||
// Add the recently uploaded file to the live indexing queue.
|
||||
//
|
||||
// Limit the queue to some maximum so that we don't keep growing
|
||||
@@ -113,10 +114,10 @@ export class MLWorker {
|
||||
// live queue is just an optimization: if a file doesn't get indexed via
|
||||
// the live queue, it'll later get indexed anyway when we backfill.
|
||||
if (this.liveQ.length < 50) {
|
||||
this.liveQ.push(file);
|
||||
this.liveQ.push({ enteFile, uploadItem });
|
||||
this.wakeUp();
|
||||
} else {
|
||||
log.debug(() => "Ignoring live item since liveQ is full");
|
||||
log.debug(() => "Ignoring upload item since liveQ is full");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +153,7 @@ export class MLWorker {
|
||||
return;
|
||||
}
|
||||
|
||||
const liveQ = this.liveQ;
|
||||
const liveQ = this.liveQ.map((i) => i.enteFile);
|
||||
this.liveQ = [];
|
||||
this.state = "indexing";
|
||||
const allSuccess = await indexNextBatch(ensure(this.userAgent), liveQ);
|
||||
|
||||
Reference in New Issue
Block a user