Skip to content

Conversation

davemarco
Copy link
Contributor

@davemarco davemarco commented Aug 19, 2025

Description

Previous result count only considered the number of results in the table for presto queries. This PR allows the UI to also include the result count from server metadata. After this PR, the result count is no longer limited to 1k results, and will show the true amount of results from presto in query status header. The table is still limited to 1k results.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Ran long query and verified results >1000 in header

Summary by CodeRabbit

  • New Features

    • Search results total now includes server-provided metadata, improving accuracy and consistency across engines.
    • Results status updates earlier to reflect the total count as soon as metadata is available.
  • Style

    • Label in Search Query Status changed from “Search job #” to “Search job” for clearer display.

Copy link
Contributor

coderabbitai bot commented Aug 19, 2025

Walkthrough

Adds client support for a server-provided total-results metadata count: new numSearchResultsMetadata state and updater, a renamed hook that populates it from results metadata, UI change to compute max across metadata/timeline/table, and a minor label spacing change in SearchQueryStatus. Hook usage updated in SearchPage.

Changes

Cohort / File(s) Summary
Search state: metadata count & hook rename
components/webui/client/src/pages/SearchPage/SearchState/index.tsx, components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts
Add numSearchResultsMetadata and updateNumSearchResultsMetadata to the search store; rename hook useUiUpdateOnDoneSignaluseUpdateStateWithMetadata; hook updates metadata count when resultsMetadata.numTotalResults is present; preserve DONE/FAILED flows; update deps and docs.
Search page integration
components/webui/client/src/pages/SearchPage/index.tsx
Replace import and invocation of useUiUpdateOnDoneSignal() with useUpdateStateWithMetadata().
Search query status UI
components/webui/client/src/pages/SearchPage/SearchQueryStatus/Results.tsx, components/webui/client/src/pages/SearchPage/SearchQueryStatus/index.tsx
Results.tsx: include metadata count in numResults = max(metadata, timeline, table) and add numSearchResultsMetadata to memo deps; expand explanatory comments. index.tsx: adjust label rendering from "Search job #" to "Search job" with explicit spacing around searchJobId.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant UI as SearchPage
  participant HK as useUpdateStateWithMetadata
  participant ST as Search Store
  participant SV as Server

  U->>UI: Start search
  UI->>SV: Submit search
  SV-->>UI: Stream rows + resultsMetadata(numTotalResults)
  UI->>HK: Hook observes signal/metadata
  HK->>ST: updateNumSearchResultsMetadata(numTotalResults)
  Note right of ST #DDEBF7: Store holds table/timeline/metadata counts
  HK->>UI: Dispatch DONE/FAILED UI state
  UI->>UI: Results.tsx computes numResults = max(metadata, timeline, table)
  UI-->>U: Render status and counts
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • kirkrodrigues

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 330ef3e and 8e8ef0f.

📒 Files selected for processing (1)
  • components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

⚙️ CodeRabbit configuration file

  • Prefer false == <expression> rather than !<expression>.

Files:

  • components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts
🧠 Learnings (2)
📚 Learning: 2025-06-09T17:15:30.309Z
Learnt from: junhaoliao
PR: y-scope/clp#962
File: components/log-viewer-webui/client/src/pages/SearchPage/SearchQueryStatus/Results.tsx:22-26
Timestamp: 2025-06-09T17:15:30.309Z
Learning: When using Zustand stores in React components, always use specific selectors (e.g., `useStore(state => state.property)`) instead of destructuring the entire state object to prevent unnecessary re-renders. This is especially important as state stores grow in complexity.

Applied to files:

  • components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts
📚 Learning: 2025-07-18T20:00:50.288Z
Learnt from: hoophalab
PR: y-scope/clp#1108
File: components/webui/client/src/pages/SearchPage/SearchControls/Presto/SqlQueryInput/index.tsx:15-15
Timestamp: 2025-07-18T20:00:50.288Z
Learning: In the y-scope/clp React webui client codebase, for Zustand store usage: use `useStore.getState().method` for callbacks since the output is not reactive and doesn't need state as a dependency in the hook, and use `useStore((state) => state.property)` with proper selectors for reactive components that need to re-render when state changes.

Applied to files:

  • components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: lint-check (macos-15)
  • GitHub Check: lint-check (ubuntu-24.04)
🔇 Additional comments (5)
components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts (5)

20-24: Docstring matches behaviour

The updated description accurately reflects the hook’s responsibilities. No action needed.


29-29: No-op change

Whitespace-only change. No action.


69-69: Dependency array completeness looks good

Including updateNumSearchResultsMetadata prevents stale closures. With selectors applied, these function refs should remain stable.


73-73: Export is consistent with new hook name

Exporting useUpdateStateWithMetadata aligns with its import sites per the PR summary. No further changes needed here.


53-61: notification.showProgress support confirmed

Ant Design’s notification API introduced the showProgress option in version 5.18.0, and our project’s dependency on "antd": "^5.24.5" includes that feature. No changes are required—showProgress: true is safe to use. (github.com)

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@davemarco davemarco requested a review from hoophalab August 19, 2025 18:02
@davemarco davemarco marked this pull request as ready for review August 19, 2025 18:02
@davemarco davemarco requested a review from a team as a code owner August 19, 2025 18:02
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
components/webui/client/src/pages/SearchPage/SearchQueryStatus/index.tsx (1)

27-32: Missing space after label and inconsistent capitalisation (“ID”)

Currently renders as “Search job id:123 found”. Add a space after the colon and capitalise “ID”.

Apply this diff:

-                    Search job id:
+                    Search job ID:{" "}
                     {searchJobId}
                     {" "}
                     found
                     {" "}
components/webui/client/src/pages/SearchPage/SearchQueryStatus/Results.tsx (2)

22-38: Guard against invalid/negative counts and stale metadata dominance

  • Consider clamping at 0 to handle defensive cases (e.g., transient negatives) and avoid showing “-1”.
  • Because max() includes metadata, stale large metadata from a previous query can dominate until new metadata arrives. Resetting the metadata count at the start of a new results set in useUpdateStateWithMetadata.ts (see separate comment) will prevent this.

Apply this diff:

-    const numResults = useMemo(
-        () => Math.max(numSearchResultsMetadata, numSearchResultsTimeline, numSearchResultsTable),
+    const numResults = useMemo(
+        () => Math.max(
+            0,
+            numSearchResultsMetadata,
+            numSearchResultsTimeline,
+            numSearchResultsTable
+        ),
         [
             numSearchResultsMetadata,
             numSearchResultsTimeline,
             numSearchResultsTable,
         ]
     );

31-38: useMemo isn’t buying much here

Computing Math.max of three numbers is trivial; useMemo adds complexity with negligible benefit. Consider inlining numResults without memoisation.

Apply this diff:

-    const numResults = useMemo(
-        () => Math.max(
-            0,
-            numSearchResultsMetadata,
-            numSearchResultsTimeline,
-            numSearchResultsTable
-        ),
-        [
-            numSearchResultsMetadata,
-            numSearchResultsTimeline,
-            numSearchResultsTable,
-        ]
-    );
+    const numResults = Math.max(
+        0,
+        numSearchResultsMetadata,
+        numSearchResultsTimeline,
+        numSearchResultsTable
+    );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 51eaeeb and 6b9cb77.

📒 Files selected for processing (5)
  • components/webui/client/src/pages/SearchPage/SearchQueryStatus/Results.tsx (1 hunks)
  • components/webui/client/src/pages/SearchPage/SearchQueryStatus/index.tsx (1 hunks)
  • components/webui/client/src/pages/SearchPage/SearchState/index.tsx (4 hunks)
  • components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts (2 hunks)
  • components/webui/client/src/pages/SearchPage/index.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

⚙️ CodeRabbit Configuration File

  • Prefer false == <expression> rather than !<expression>.

Files:

  • components/webui/client/src/pages/SearchPage/SearchQueryStatus/Results.tsx
  • components/webui/client/src/pages/SearchPage/SearchQueryStatus/index.tsx
  • components/webui/client/src/pages/SearchPage/index.tsx
  • components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts
  • components/webui/client/src/pages/SearchPage/SearchState/index.tsx
🔇 Additional comments (7)
components/webui/client/src/pages/SearchPage/SearchState/index.tsx (3)

47-51: Good addition and clear documentation

Adding numSearchResultsMetadata with a concise description aligns well with the PR objective.


106-106: Updater naming and symmetry LGTM

The updater name matches existing patterns (table/timeline) and reads clearly in downstream code.


127-129: Setter implementation is correct; consider guarding against NaN upstream

The setter is fine. Upstream, ensure only finite, non-negative numbers flow in (see suggestions in useUpdateStateWithMetadata.ts) so UI doesn’t momentarily show “NaN” or negative counts if the backend sends unexpected values.

components/webui/client/src/pages/SearchPage/index.tsx (1)

11-21: Hook rename integration verified

The named export in useUpdateStateWithMetadata.ts matches the import in SearchPage/index.tsx. No further action needed.

• components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts (line 61):
export { useUpdateStateWithMetadata };

components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts (3)

15-20: Docstring aligns with behaviour change

Accurately describes UI state transitions and the new metadata-driven count update.


55-58: Dependency array is correct; no extra deps needed

Including updateNumSearchResultsMetadata is necessary. The ref does not need to be added.


61-62: Export name matches usage

The named export aligns with the new import in SearchPage.

const SEARCH_STATE_DEFAULT = Object.freeze({
aggregationJobId: null,
cachedDataset: null,
numSearchResultsMetadata: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Consider 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 --type=tsx support:


🏁 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 updateNumSearchResultsMetadata is only invoked when resultsMetadata.numTotalResults is defined—there’s no explicit reset to 0 when a query starts or when a new results set (_id) arrives. As a result, if the first payload of a new query omits numTotalResults, the previous (larger) value will persist and skew any max() calculations in Results.tsx.

Please add an explicit reset to 0 in useUpdateStateWithMetadata.ts, for example:

• 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
In
components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts
around where resultsMetadata is handled (related to lines near the current
numSearchResultsMetadata usage), the metadata counter is never explicitly reset
when a new query or results set (_id) begins, allowing stale larger values to
persist; modify the effect that reads resultsMetadata so it first calls
updateNumSearchResultsMetadata(0) to clear the count, then only sets the real
value if resultsMetadata.numTotalResults is defined, and ensure the effect
depends on the query identifier (e.g., resultsMetadata._id) so the reset runs
for each new query.

Comment on lines +21 to +24
const useUpdateStateWithMetadata = () => {
const {updateSearchUiState, updateNumSearchResultsMetadata} = useSearchStore();
const resultsMetadata = useResultsMetadata();

Copy link
Contributor

Choose a reason for hiding this comment

The 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
In
components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts
around lines 21 to 24, the current destructuring of useSearchStore subscribes to
the whole store and causes unnecessary re-renders; instead, select only the
specific actions you need from the store (e.g. use the selector form of
useSearchStore to pick updateSearchUiState and updateNumSearchResultsMetadata,
or call useSearchStore twice to read each action separately) so the component
only subscribes to those actions; ensure the selected action references are
stable (wrap callbacks where needed) and remove the current broad destructuring.

Copy link
Contributor

@hoophalab hoophalab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks mostly good but can we also implement #1210 in this PR?

@davemarco
Copy link
Contributor Author

im still thinking about how to do that. Im not sure if we should do what was suggested, or just a icon with tooltip. Or just render some message at the bottom of the table. Either way it will need to be conditionally rendered so may be much for this PR?

Anyways we probably shouldnt merge this PR until after release, to prevent issues with release

hoophalab
hoophalab previously approved these changes Aug 20, 2025
Copy link
Contributor

@hoophalab hoophalab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm
Validations:

  1. presto search now shows the correct found results
  2. clp search behaves the same as before

…/index.tsx

Co-authored-by: hoophalab <200652805+hoophalab@users.noreply.github.com>
Copy link
Member

@kirkrodrigues kirkrodrigues left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferring to @hoophalab's review.

For the PR title, how about:

feat(webui): Display total result count rather than UI table row count for Presto queries.

@hoophalab hoophalab changed the title feat(webui): Set number results using server metadata to display total result count for presto queries. feat(webui): Display total result count rather than UI table row count for Presto queries. Aug 25, 2025
@hoophalab hoophalab merged commit 7f6bb6d into y-scope:main Aug 25, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants