add support to detect unsupported platform and stop trying to run clip

This commit is contained in:
Abhinav 2023-11-21 12:12:28 +05:30
parent 13661994dd
commit c029e8d503
4 changed files with 30 additions and 9 deletions

View file

@ -335,7 +335,6 @@ export default function Gallery() {
setHiddenFiles(hiddenFiles);
setCollections(normalCollections);
setHiddenCollections(hiddenCollections);
void ClipService.setupOnFileUploadListener();
await syncWithRemote(true);
setIsFirstLoad(false);
setJustSignedUp(false);
@ -344,6 +343,7 @@ export default function Gallery() {
syncWithRemote(false, true);
}, SYNC_INTERVAL_IN_MICROSECONDS);
if (isElectron()) {
void ClipService.setupOnFileUploadListener();
ElectronAPIs.registerForegroundEventListener(() => {
syncWithRemote(false, true);
});
@ -354,8 +354,8 @@ export default function Gallery() {
clearInterval(syncInterval.current);
if (isElectron()) {
ElectronAPIs.registerForegroundEventListener(() => {});
ClipService.removeOnFileUploadListener();
}
ClipService.removeOnFileUploadListener();
};
}, []);
@ -722,8 +722,8 @@ export default function Gallery() {
await syncTrash(collections, setTrashedFiles);
await syncEntities();
await syncMapEnabled();
if (isElectron()) {
await syncEmbeddings();
await syncEmbeddings();
if (ClipService.isPlatformSupported()) {
void ClipService.scheduleImageEmbeddingExtraction();
}
} catch (e) {

View file

@ -7,7 +7,6 @@ import { getAllLocalFiles, getLocalFiles } from './fileService';
import downloadManager from './downloadManager';
import { logError } from '@ente/shared/sentry';
import { addLogLine } from '@ente/shared/logging';
import isElectron from 'is-electron';
import { Events, eventBus } from '@ente/shared/events';
import PQueue from 'p-queue';
import { EnteFile } from 'types/file';
@ -40,6 +39,7 @@ class ClipServiceImpl {
private onFileUploadedHandler:
| ((arg: { enteFile: EnteFile; localFile: globalThis.File }) => void)
| null = null;
private unsupportedPlatform = false;
constructor() {
this.liveEmbeddingExtractionQueue = new PQueue({
@ -47,9 +47,13 @@ class ClipServiceImpl {
});
}
isPlatformSupported = () => {
return !this.unsupportedPlatform;
};
setupOnFileUploadListener = async () => {
try {
if (!isElectron()) {
if (this.unsupportedPlatform) {
return;
}
if (this.onFileUploadedHandler) {
@ -148,6 +152,12 @@ class ClipServiceImpl {
private runClipEmbeddingExtraction = async (canceller: AbortController) => {
try {
if (this.unsupportedPlatform) {
addLogLine(
`skipping clip embedding extraction, platform unsupported`
);
return;
}
const user = getData(LS_KEYS.USER);
if (!user) {
return;
@ -188,12 +198,23 @@ class ClipServiceImpl {
`successfully put clip embedding to server for file: ${file.metadata.title} fileID: ${file.id}`
);
} catch (e) {
if (e.message !== CustomError.REQUEST_CANCELLED) {
if (e?.message !== CustomError.REQUEST_CANCELLED) {
logError(
e,
'failed to extract clip embedding for file'
);
}
if (
e?.message?.includes(CustomError.UNSUPPORTED_PLATFORM)
) {
this.unsupportedPlatform = true;
}
if (
e?.message === CustomError.REQUEST_CANCELLED ||
e?.message?.includes(CustomError.UNSUPPORTED_PLATFORM)
) {
throw e;
}
}
}
} catch (e) {

View file

@ -32,7 +32,6 @@ import {
computeClipMatchScore,
getLocalClipImageEmbeddings,
} from './clipService';
import isElectron from 'is-electron';
const DIGITS = new Set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']);
@ -291,7 +290,7 @@ async function getThingSuggestion(searchPhrase: string): Promise<Suggestion[]> {
}
async function getClipSuggestion(searchPhrase: string): Promise<Suggestion> {
if (!isElectron()) {
if (!ClipService.isPlatformSupported()) {
return null;
}
const clipResults = await searchClip(searchPhrase);

View file

@ -85,6 +85,7 @@ export const CustomError = {
CLIENT_ERROR: 'client error',
ServerError: 'server error',
FILE_NOT_FOUND: 'file not found',
UNSUPPORTED_PLATFORM: 'Unsupported platform',
};
export function handleUploadError(error: any): Error {