-
Notifications
You must be signed in to change notification settings - Fork 82
feat(webui): Display total result count rather than UI table row count for Presto queries. #1236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
4ce6adc
6b9cb77
5afa51a
330ef3e
a7b9f16
8e8ef0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import {SEARCH_UI_STATE} from "./typings"; | |
const SEARCH_STATE_DEFAULT = Object.freeze({ | ||
aggregationJobId: null, | ||
cachedDataset: null, | ||
numSearchResultsMetadata: 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainConsider resetting metadata count at query start to avoid stale max() values Initialising to 0 is fine, but if a new query begins and the first metadata payload lacks numTotalResults, the previous query’s (possibly large) metadata count can linger and dominate the max(metadata, timeline, table) in Results.tsx. Ensure this field is explicitly reset to 0 on new query start or when a new results set (_id) is detected. Run this to find where the metadata count is reset on query start and whether a 0 reset exists: 🏁 Script executed: #!/bin/bash
set -euo pipefail
# All call sites of updateNumSearchResultsMetadata
rg -nP -C2 --type=ts --type=tsx '\bupdateNumSearchResultsMetadata\s*\('
# Explicit resets to 0
rg -nP -C3 --type=ts --type=tsx 'updateNumSearchResultsMetadata\s*\(\s*0\s*\)' Length of output: 121 I’ll retry the grep without relying on 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Find all call sites of updateNumSearchResultsMetadata in .ts and .tsx files
rg -nP -C2 '\bupdateNumSearchResultsMetadata\s*\(' -g '*.ts' -g '*.tsx'
# Find any explicit resets to 0
rg -nP -C3 'updateNumSearchResultsMetadata\s*\(\s*0\s*\)' -g '*.ts' -g '*.tsx' Length of output: 783 Ensure metadata count is reset on every new query The handler Please add an explicit reset to 0 in • File: components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts useEffect(() => {
// Reset metadata count on each new query (or when _id changes)
updateNumSearchResultsMetadata(0);
if (typeof resultsMetadata.numTotalResults !== "undefined") {
updateNumSearchResultsMetadata(resultsMetadata.numTotalResults);
}
}, [resultsMetadata._id /* or the relevant query identifier */]); This guarantees stale values are cleared before processing each new result set. 🤖 Prompt for AI Agents
|
||
numSearchResultsTable: 0, | ||
numSearchResultsTimeline: 0, | ||
queryIsCaseSensitive: false, | ||
|
@@ -43,6 +44,11 @@ interface SearchState { | |
*/ | ||
cachedDataset: Nullable<string>; | ||
|
||
/** | ||
* The number of search results from server metadata. | ||
*/ | ||
numSearchResultsMetadata: number; | ||
|
||
/** | ||
* The number of search table results. | ||
*/ | ||
|
@@ -97,6 +103,7 @@ interface SearchState { | |
|
||
updateAggregationJobId: (id: string | null) => void; | ||
updateCachedDataset: (dataset: string) => void; | ||
updateNumSearchResultsMetadata: (num: number) => void; | ||
updateNumSearchResultsTable: (num: number) => void; | ||
updateNumSearchResultsTimeline: (num: number) => void; | ||
updateQueryIsCaseSensitive: (newValue: boolean) => void; | ||
|
@@ -117,6 +124,9 @@ const useSearchStore = create<SearchState>((set) => ({ | |
updateCachedDataset: (dataset) => { | ||
set({cachedDataset: dataset}); | ||
}, | ||
updateNumSearchResultsMetadata: (num) => { | ||
set({numSearchResultsMetadata: num}); | ||
}, | ||
updateNumSearchResultsTable: (num) => { | ||
set({numSearchResultsTable: num}); | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,18 +12,25 @@ import {useResultsMetadata} from "./useResultsMetadata"; | |
|
||
|
||
/** | ||
* Custom hook to update the UI state to `DONE` when the results metadata signal indicates | ||
* that the query is complete, or `FAILED` if the query fails. If there is an error, it will | ||
* also display a notification with the error message. | ||
* Custom hook to update the client state based on results metadata from the server. | ||
* - Sets the UI state to `DONE` when the results metadata signal indicates that the query is | ||
* complete, or `FAILED` if the query fails. If there is an error, it will display a notification | ||
* with the error message. | ||
* - Updates the number of search results from the metadata. | ||
*/ | ||
const useUiUpdateOnDoneSignal = () => { | ||
const {updateSearchUiState} = useSearchStore(); | ||
const useUpdateStateWithMetadata = () => { | ||
const {updateSearchUiState, updateNumSearchResultsMetadata} = useSearchStore(); | ||
const resultsMetadata = useResultsMetadata(); | ||
|
||
Comment on lines
+26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Select store actions with selectors to avoid re-rendering on every state change Destructuring the whole store subscribes to all state changes, causing SearchPage to re-render frequently. Select only the actions needed. Apply this diff: -const useUpdateStateWithMetadata = () => {
- const {updateSearchUiState, updateNumSearchResultsMetadata} = useSearchStore();
+const useUpdateStateWithMetadata = () => {
+ const updateSearchUiState = useSearchStore((s) => s.updateSearchUiState);
+ const updateNumSearchResultsMetadata = useSearchStore((s) => s.updateNumSearchResultsMetadata);
const resultsMetadata = useResultsMetadata(); 🤖 Prompt for AI Agents
|
||
useEffect(() => { | ||
if (null === resultsMetadata) { | ||
return; | ||
} | ||
|
||
if ("undefined" !== typeof resultsMetadata.numTotalResults) { | ||
updateNumSearchResultsMetadata(resultsMetadata.numTotalResults); | ||
} | ||
|
||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
switch (resultsMetadata.lastSignal) { | ||
case SEARCH_SIGNAL.RESP_DONE: | ||
case PRESTO_SEARCH_SIGNAL.FINISHED: | ||
|
@@ -47,7 +54,8 @@ const useUiUpdateOnDoneSignal = () => { | |
}, [ | ||
resultsMetadata, | ||
updateSearchUiState, | ||
updateNumSearchResultsMetadata, | ||
]); | ||
}; | ||
|
||
export {useUiUpdateOnDoneSignal}; | ||
export {useUpdateStateWithMetadata}; |
Uh oh!
There was an error while loading. Please reload this page.