Skip to content

armgit / ente

Public Imported from GitHub
0

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

chore(SearchBar):added-logs-for-monitoring

Aswin Asok0ff5f1efddb2
diff --git a/web/packages/new/photos/components/SearchBar.tsx b/web/packages/new/photos/components/SearchBar.tsx
index 15fb12be51..047e757bd1 100644
--- a/web/packages/new/photos/components/SearchBar.tsx
+++ b/web/packages/new/photos/components/SearchBar.tsx
@@ -17,6 +17,7 @@ import {
import { EnteLogo, EnteLogoBox } from "ente-base/components/EnteLogo";
import type { ButtonishProps } from "ente-base/components/mui";
import { useIsSmallWidth } from "ente-base/components/utils/hooks";
+import log from "ente-base/log";
import {
hlsGenerationStatusSnapshot,
isHLSGenerationSupported,
@@ -186,6 +187,10 @@ const SearchInput: React.FC<Omit<SearchBarProps, "onShowSearchInput">> = ({
}, []);
const handleChange = (value: SearchOption | null) => {
+ log.debug(
+ () =>
+ `[SearchBar] Option selected: ${value?.suggestion.type ?? "none"} - "${value?.suggestion.label ?? ""}"`,
+ );
const type = value?.suggestion.type;
// Collection and people suggestions are handled differently - our
// caller will switch to the corresponding view, dismissing search.
@@ -218,10 +223,14 @@ const SearchInput: React.FC<Omit<SearchBarProps, "onShowSearchInput">> = ({
const handleInputChange = (value: string, actionMeta: InputActionMeta) => {
if (actionMeta.action == "input-change") {
+ log.debug(() => `[SearchBar] Input changed: "${value}"`);
setInputValue(value);
// If the input is cleared, also clear the selected value.
if (value === "") {
+ log.debug(
+ () => "[SearchBar] Input cleared, resetting selection",
+ );
setValue(null);
setInputValue("");
// Notify parent but don't exit search mode on mobile
@@ -233,6 +242,7 @@ const SearchInput: React.FC<Omit<SearchBarProps, "onShowSearchInput">> = ({
};
const resetSearch = () => {
+ log.debug(() => "[SearchBar] Resetting search state");
// Dismiss the search menu if it is open.
selectRef.current?.blur();
@@ -255,11 +265,16 @@ const SearchInput: React.FC<Omit<SearchBarProps, "onShowSearchInput">> = ({
};
const handleFocus = () => {
+ log.debug(() => "[SearchBar] Search input focused");
setIsFocused(true);
// A workaround to show the suggestions again for the current non-empty
// search string if the user focuses back on the input field after
// moving focus elsewhere.
if (inputValue) {
+ log.debug(
+ () =>
+ `[SearchBar] Re-triggering search for existing input: "${inputValue}"`,
+ );
selectRef.current?.onInputChange(inputValue, {
action: "set-value",
prevInputValue: "",
@@ -268,6 +283,7 @@ const SearchInput: React.FC<Omit<SearchBarProps, "onShowSearchInput">> = ({
};
const handleBlur = () => {
+ log.debug(() => "[SearchBar] Search input blurred");
setIsFocused(false);
};
@@ -288,16 +304,39 @@ const SearchInput: React.FC<Omit<SearchBarProps, "onShowSearchInput">> = ({
onFocus={handleFocus}
onBlur={handleBlur}
placeholder={t("search_hint")}
- noOptionsMessage={({ inputValue }) =>
- inputValue ? (
- t("no_results")
- ) : shouldShowEmptyState(inputValue) ? (
- <EmptyState
- onSelectPeople={handleSelectPeople}
- onSelectPerson={handleSelectPerson}
- />
- ) : null
- }
+ loadingMessage={({ inputValue }) => {
+ log.debug(
+ () =>
+ `[SearchBar] loadingMessage: Loading results for "${inputValue}"`,
+ );
+ return t("loading");
+ }}
+ noOptionsMessage={({ inputValue }) => {
+ if (inputValue) {
+ log.debug(
+ () =>
+ `[SearchBar] noOptionsMessage: No results for "${inputValue}"`,
+ );
+ return t("no_results");
+ }
+ if (shouldShowEmptyState(inputValue)) {
+ log.debug(
+ () =>
+ "[SearchBar] noOptionsMessage: Showing empty state",
+ );
+ return (
+ <EmptyState
+ onSelectPeople={handleSelectPeople}
+ onSelectPerson={handleSelectPerson}
+ />
+ );
+ }
+ log.debug(
+ () =>
+ "[SearchBar] noOptionsMessage: Returning null (no menu content)",
+ );
+ return null;
+ }}
/>
{isInSearchMode && (
@@ -321,12 +360,32 @@ const SearchInputWrapper = styled("div")`
`;
const loadOptions = pDebounce(async (input: string) => {
- const [sidebarActions, photoOptions] = await Promise.all([
- sidebarSearchOptionsForString(input),
- searchOptionsForString(input),
- ]);
+ log.debug(() => ["[SearchBar] Loading search options", { input }]);
+ const startTime = performance.now();
+
+ try {
+ const [sidebarActions, photoOptions] = await Promise.all([
+ sidebarSearchOptionsForString(input),
+ searchOptionsForString(input),
+ ]);
+
+ const duration = performance.now() - startTime;
+ log.debug(
+ () =>
+ `[SearchBar] Search options loaded in ${duration.toFixed(0)}ms: ` +
+ `${photoOptions.length} photo options, ${sidebarActions.length} sidebar actions`,
+ );
- return [...photoOptions, ...sidebarActions];
+ return [...photoOptions, ...sidebarActions];
+ } catch (e) {
+ const duration = performance.now() - startTime;
+ log.error(
+ `[SearchBar] Failed to load search options after ${duration.toFixed(0)}ms`,
+ e,
+ );
+ // Re-throw so react-select can handle it, but now we have visibility
+ throw e;
+ }
}, 250);
// const loadOptions = pDebounce(searchOptionsForString, 250);
@@ -482,11 +541,26 @@ const shouldShowEmptyState = (inputValue: string) => {
if (!isMLSupported && !isHLSGenerationSupported) {
// Neither of ML or HLS generation is supported on current client. This
// is the code path for web.
+ log.debug(
+ () =>
+ "[SearchBar] shouldShowEmptyState: false (ML and HLS not supported)",
+ );
return false;
}
const mlStatus = mlStatusSnapshot();
const vpStatus = hlsGenerationStatusSnapshot();
+ log.debug(() => [
+ "[SearchBar] shouldShowEmptyState check",
+ {
+ isMLSupported,
+ isHLSGenerationSupported,
+ mlPhase: mlStatus?.phase ?? "undefined",
+ vpEnabled: vpStatus?.enabled ?? false,
+ vpStatus: vpStatus?.enabled ? vpStatus.status : "disabled",
+ },
+ ]);
+
if (
(!mlStatus || mlStatus.phase == "disabled") &&
(!vpStatus?.enabled || vpStatus.status != "processing")
@@ -494,10 +568,15 @@ const shouldShowEmptyState = (inputValue: string) => {
// ML is either not supported or currently disabled AND video processing
// is either not supported or currently not happening. Don't show the
// empty state.
+ log.debug(
+ () =>
+ "[SearchBar] shouldShowEmptyState: false (ML disabled, no video processing)",
+ );
return false;
}
// Show it otherwise.
+ log.debug(() => "[SearchBar] shouldShowEmptyState: true");
return true;
};
@@ -512,6 +591,16 @@ const EmptyState: React.FC<
const people = usePeopleStateSnapshot()?.visiblePeople;
const vpStatus = useHLSGenerationStatusSnapshot();
+ log.debug(() => [
+ "[SearchBar] EmptyState render",
+ {
+ mlPhase: mlStatus?.phase ?? "undefined",
+ peopleCount: people?.length ?? 0,
+ vpEnabled: vpStatus?.enabled ?? false,
+ vpStatus: vpStatus?.enabled ? vpStatus.status : "disabled",
+ },
+ ]);
+
let label: string | undefined;
switch (mlStatus?.phase) {
case undefined:
@@ -520,19 +609,26 @@ const EmptyState: React.FC<
// If ML is not running, see if video processing is.
if (vpStatus?.enabled && vpStatus.status == "processing") {
label = t("processing_videos_status");
+ log.debug(
+ () => "[SearchBar] Status: Processing videos in progress",
+ );
}
break;
case "scheduled":
label = t("indexing_scheduled");
+ log.debug(() => "[SearchBar] Status: Photo indexing scheduled");
break;
case "indexing":
label = t("indexing_photos");
+ log.debug(() => "[SearchBar] Status: Indexing photos in progress");
break;
case "fetching":
label = t("indexing_fetching");
+ log.debug(() => "[SearchBar] Status: Fetching data for indexing");
break;
case "clustering":
label = t("indexing_people");
+ log.debug(() => "[SearchBar] Status: Clustering people/faces");
break;
}