Browse Source

Fix face indexing status update issue (#1542)

Vishnu Mohandas 1 year ago
parent
commit
322c70aaa8

+ 6 - 0
apps/photos/src/components/Search/SearchBar/searchInput/index.tsx

@@ -34,6 +34,7 @@ import { t } from 'i18next';
 import memoize from 'memoize-one';
 import { LocationTagData } from 'types/entity';
 import { FILE_TYPE } from 'constants/file';
+import { addLogLine } from '@ente/shared/logging';
 
 interface Iprops {
     isOpen: boolean;
@@ -64,10 +65,15 @@ export default function SearchInput(props: Iprops) {
 
     useEffect(() => {
         refreshDefaultOptions();
+        const t = setInterval(() => refreshDefaultOptions(), 2000);
+        return () => clearInterval(t);
     }, []);
 
     async function refreshDefaultOptions() {
+        const t = Date.now();
+        addLogLine('refreshDefaultOptions called');
         const defaultOptions = await getDefaultOptions(props.files);
+        addLogLine(`refreshDefaultOptions end time: ${Date.now() - t}ms`);
         setDefaultOptions(defaultOptions);
     }
 

+ 28 - 22
apps/photos/src/services/searchService.ts

@@ -42,7 +42,7 @@ export const getDefaultOptions = async (files: EnteFile[]) => {
     return [
         await getIndexStatusSuggestion(),
         ...convertSuggestionsToOptions(await getAllPeopleSuggestion(), files),
-    ];
+    ].filter((t) => !!t);
 };
 
 export const getAutoCompleteSuggestions =
@@ -176,7 +176,9 @@ function getYearSuggestion(searchPhrase: string): Suggestion[] {
 
 export async function getAllPeopleSuggestion(): Promise<Array<Suggestion>> {
     try {
+        addLogLine('getAllPeopleSuggestion called');
         const people = await getAllPeople(200);
+        addLogLine(`found people: ${people?.length ?? 0}`);
         return people.map((person) => ({
             label: person.name,
             type: SuggestionType.PERSON,
@@ -190,28 +192,32 @@ export async function getAllPeopleSuggestion(): Promise<Array<Suggestion>> {
 }
 
 export async function getIndexStatusSuggestion(): Promise<Suggestion> {
-    const config = await getMLSyncConfig();
-    const indexStatus = await mlIDbStorage.getIndexStatus(config.mlVersion);
-
-    let label;
-    if (!indexStatus.localFilesSynced) {
-        label = t('INDEXING_SCHEDULED');
-    } else if (indexStatus.outOfSyncFilesExists) {
-        label = t('ANALYZING_PHOTOS', {
-            indexStatus,
-        });
-    } else if (!indexStatus.peopleIndexSynced) {
-        label = t('INDEXING_PEOPLE', { indexStatus });
-    } else {
-        label = t('INDEXING_DONE', { indexStatus });
-    }
+    try {
+        const config = await getMLSyncConfig();
+        const indexStatus = await mlIDbStorage.getIndexStatus(config.mlVersion);
+
+        let label;
+        if (!indexStatus.localFilesSynced) {
+            label = t('INDEXING_SCHEDULED');
+        } else if (indexStatus.outOfSyncFilesExists) {
+            label = t('ANALYZING_PHOTOS', {
+                indexStatus,
+            });
+        } else if (!indexStatus.peopleIndexSynced) {
+            label = t('INDEXING_PEOPLE', { indexStatus });
+        } else {
+            label = t('INDEXING_DONE', { indexStatus });
+        }
 
-    return {
-        label,
-        type: SuggestionType.INDEX_STATUS,
-        value: indexStatus,
-        hide: true,
-    };
+        return {
+            label,
+            type: SuggestionType.INDEX_STATUS,
+            value: indexStatus,
+            hide: true,
+        };
+    } catch (e) {
+        logError(e, 'getIndexStatusSuggestion failed');
+    }
 }
 
 function getDateSuggestion(searchPhrase: string): Suggestion[] {