Fix embedding sync blocked (#1451)

This commit is contained in:
Abhinav Kumar 2023-11-20 12:24:37 +05:30 committed by GitHub
commit 814c1ebaf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View file

@ -14,6 +14,8 @@ import HTTPService from '@ente/shared/network/HTTPService';
import { getToken } from '@ente/shared/storage/localStorage/helpers';
import { getLatestVersionEmbeddings } from 'utils/embedding';
import { getLocalTrashedFiles } from './trashService';
import { getLocalCollections } from './collectionService';
import { CustomError } from '@ente/shared/error';
const ENDPOINT = getEndpoint();
@ -42,6 +44,7 @@ export const syncEmbeddings = async () => {
try {
let embeddings = await getLocalEmbeddings();
const localFiles = await getAllLocalFiles();
const hiddenAlbums = await getLocalCollections('hidden');
const localTrashFiles = await getLocalTrashedFiles();
const fileIdToKeyMap = new Map<number, string>();
[...localFiles, ...localTrashFiles].forEach((file) => {
@ -67,7 +70,7 @@ export const syncEmbeddings = async () => {
const worker = await ComlinkCryptoWorker.getInstance();
const fileKey = fileIdToKeyMap.get(embedding.fileID);
if (!fileKey) {
throw Error('File key not found');
throw Error(CustomError.FILE_NOT_FOUND);
}
const decryptedData = await worker.decryptEmbedding(
encryptedEmbedding,
@ -80,7 +83,14 @@ export const syncEmbeddings = async () => {
embedding: decryptedData,
} as Embedding;
} catch (e) {
logError(e, 'decryptEmbedding failed for file');
let info: Record<string, unknown>;
if (e.message === CustomError.FILE_NOT_FOUND) {
const hasHiddenAlbums = hiddenAlbums?.length > 0;
info = {
hasHiddenAlbums,
};
}
logError(e, 'decryptEmbedding failed for file', info);
}
})
);

View file

@ -3,6 +3,9 @@ import { Embedding } from 'types/embedding';
export const getLatestVersionEmbeddings = (embeddings: Embedding[]) => {
const latestVersionEntities = new Map<number, Embedding>();
embeddings.forEach((embedding) => {
if (!embedding?.fileID) {
return;
}
const existingEmbeddings = latestVersionEntities.get(embedding.fileID);
if (
!existingEmbeddings ||

View file

@ -84,6 +84,7 @@ export const CustomError = {
TWO_FACTOR_ENABLED: 'two factor enabled',
CLIENT_ERROR: 'client error',
ServerError: 'server error',
FILE_NOT_FOUND: 'file not found',
};
export function handleUploadError(error: any): Error {