From 9c60fe6f3fd258d385cdc0f3abee4e29086fed10 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Wed, 29 May 2024 12:22:58 +0530 Subject: [PATCH] logout --- web/apps/photos/src/services/face/db.ts | 10 ++++++---- web/apps/photos/src/services/logout.ts | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/web/apps/photos/src/services/face/db.ts b/web/apps/photos/src/services/face/db.ts index adaf097cee..5c23bb19f6 100644 --- a/web/apps/photos/src/services/face/db.ts +++ b/web/apps/photos/src/services/face/db.ts @@ -79,8 +79,8 @@ interface FileStatus { * Note that this is module specific state, so the main thread and each worker * thread that calls the functions in this module will get their own independent * connection. To ensure that all connections get torn down correctly, we need - * to call closeFaceDBConnection - * used to delete the database in {@link clearFaceData}. + * to call {@link closeFaceDBConnectionsIfNeeded} from both the main thread and + * all the worker threads that use this module. */ let _faceDB: ReturnType | undefined; @@ -143,14 +143,16 @@ export const closeFaceDBConnectionsIfNeeded = async () => { * * Meant to be called during logout. */ -export const clearFaceData = () => - deleteDB("face", { +export const clearFaceData = async () => { + await closeFaceDBConnectionsIfNeeded(); + return deleteDB("face", { blocked() { log.warn( "Waiting for an existing client to close their connection so that we can delete the face DB", ); }, }); +}; /** * Save the given {@link faceIndex} locally. diff --git a/web/apps/photos/src/services/logout.ts b/web/apps/photos/src/services/logout.ts index a6b155c8c2..9b664bf579 100644 --- a/web/apps/photos/src/services/logout.ts +++ b/web/apps/photos/src/services/logout.ts @@ -3,6 +3,7 @@ import { accountLogout } from "@ente/accounts/services/logout"; import { clipService } from "services/clip-service"; import DownloadManager from "./download"; import exportService from "./export"; +import { clearFaceData } from "./face/db"; import mlWorkManager from "./machineLearning/mlWorkManager"; /** @@ -35,6 +36,12 @@ export const photosLogout = async () => { log.error("Ignoring error during logout (ML)", e); } + try { + await clearFaceData(); + } catch (e) { + log.error("Ignoring error during logout (face)", e); + } + try { exportService.disableContinuousExport(); } catch (e) {