Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix issues

Abhinav6961fc7fbe51
diff --git a/apps/photos/src/services/clipService.ts b/apps/photos/src/services/clipService.ts
index 08ef8d6235..fd470876b3 100644
--- a/apps/photos/src/services/clipService.ts
+++ b/apps/photos/src/services/clipService.ts
@@ -1,8 +1,4 @@
-import {
- putEmbedding,
- getLatestEmbeddings,
- getLocalEmbeddings,
-} from './embeddingService';
+import { putEmbedding, getLocalEmbeddings } from './embeddingService';
import { getAllLocalFiles, getLocalFiles } from './fileService';
import downloadManager from './download';
import { logError } from '@ente/shared/sentry';
@@ -174,9 +170,7 @@ class ClipServiceImpl {
return;
}
const localFiles = getPersonalFiles(await getAllLocalFiles(), user);
- const existingEmbeddings = await getLatestClipImageEmbeddings(
- model
- );
+ const existingEmbeddings = await getLocalClipImageEmbeddings(model);
const pendingFiles = await getNonClipEmbeddingExtractedFiles(
localFiles,
existingEmbeddings
@@ -205,7 +199,11 @@ class ClipServiceImpl {
addLogLine(
`successfully extracted clip embedding for file: ${file.metadata.title} fileID: ${file.id} embedding length: ${embeddingData?.length}`
);
- await this.encryptAndUploadEmbedding(file, embeddingData);
+ await this.encryptAndUploadEmbedding(
+ model,
+ file,
+ embeddingData
+ );
this.onSuccessStatusUpdater();
addLogLine(
`successfully put clip embedding to server for file: ${file.metadata.title} fileID: ${file.id}`
@@ -262,7 +260,11 @@ class ClipServiceImpl {
model,
localFile
);
- await this.encryptAndUploadEmbedding(enteFile, embedding);
+ await this.encryptAndUploadEmbedding(
+ model,
+ enteFile,
+ embedding
+ );
});
addLogLine(
`successfully extracted clip embedding for file: ${enteFile.metadata.title} fileID: ${enteFile.id}`
@@ -284,6 +286,7 @@ class ClipServiceImpl {
};
private encryptAndUploadEmbedding = async (
+ model: Model,
file: EnteFile,
embeddingData: Float32Array
) => {
@@ -302,7 +305,7 @@ class ClipServiceImpl {
fileID: file.id,
encryptedEmbedding: encryptedEmbeddingData.encryptedData,
decryptionHeader: encryptedEmbeddingData.decryptionHeader,
- model: Model.GGML_CLIP,
+ model,
});
};
@@ -388,11 +391,6 @@ export const computeClipMatchScore = async (
return score;
};
-const getLatestClipImageEmbeddings = async (model: Model) => {
- const allEmbeddings = await getLatestEmbeddings();
- return allEmbeddings.filter((embedding) => embedding.model === model);
-};
-
const getClipExtractionStatus = async (
model: Model = Model.ONNX_CLIP
): Promise<ClipExtractionStatus> => {
diff --git a/apps/photos/src/services/embeddingService.ts b/apps/photos/src/services/embeddingService.ts
index 460e0d0581..382915536a 100644
--- a/apps/photos/src/services/embeddingService.ts
+++ b/apps/photos/src/services/embeddingService.ts
@@ -21,12 +21,20 @@ const ENDPOINT = getEndpoint();
const DIFF_LIMIT = 500;
-const EMBEDDINGS_TABLE = 'embeddings';
+const EMBEDDINGS_TABLE_V1 = 'embeddings';
+const EMBEDDINGS_TABLE = 'embeddings_v2';
const EMBEDDING_SYNC_TIME_TABLE = 'embedding_sync_time';
export const getLocalEmbeddings = async () => {
- const embeddings: Array<Embedding> =
- (await localForage.getItem<Embedding[]>(EMBEDDINGS_TABLE)) || [];
+ const embeddings: Array<Embedding> = await localForage.getItem<Embedding[]>(
+ EMBEDDINGS_TABLE
+ );
+ if (!embeddings) {
+ await localForage.removeItem(EMBEDDINGS_TABLE_V1);
+ await localForage.setItem(EMBEDDINGS_TABLE, []);
+ await localForage.setItem(EMBEDDING_SYNC_TIME_TABLE, 0);
+ return [];
+ }
return embeddings;
};
@@ -34,12 +42,6 @@ const getEmbeddingSyncTime = async () => {
return (await localForage.getItem<number>(EMBEDDING_SYNC_TIME_TABLE)) ?? 0;
};
-export const getLatestEmbeddings = async () => {
- await syncEmbeddings();
- const embeddings = await getLocalEmbeddings();
- return embeddings;
-};
-
export const syncEmbeddings = async () => {
try {
let embeddings = await getLocalEmbeddings();