Fix face indexing status update issue (#1542)

This commit is contained in:
Vishnu Mohandas 2024-01-11 19:55:50 +05:30 committed by GitHub
commit 322c70aaa8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 21 deletions

View file

@ -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);
}

View file

@ -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);
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 });
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,
};
} catch (e) {
logError(e, 'getIndexStatusSuggestion failed');
}
return {
label,
type: SuggestionType.INDEX_STATUS,
value: indexStatus,
hide: true,
};
}
function getDateSuggestion(searchPhrase: string): Suggestion[] {