Skip to content

Conversation

davemarco
Copy link
Contributor

@davemarco davemarco commented Aug 15, 2025

Description

PR limits the amount results actually stored in mongoDB since 1) ui only shows 1000 results max, 2) could take up lots of space for long running queries.

I tried a few design but i think this inline design is the simplest.

The total num results is updated in metadata, but the UI does not show this yet. This will be another PR.

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 with lots of results. Checked results in mongo was only 1000. checked total in results metadata was > 1000

Summary by CodeRabbit

  • New Features
    • Added a cap on stored search results (up to 1,000) to keep searches responsive during large queries.
    • Continuously tracks and updates the total number of results returned for each search, improving visibility into long-running queries.
  • Chores
    • Enhanced logging for streamed data and failures to aid troubleshooting and monitoring.
    • Improved error messages when saving results or updating metadata.
    • No changes to the public API; existing integrations continue to work as before.

Copy link
Contributor

coderabbitai bot commented Aug 15, 2025

Walkthrough

Implements per-chunk result counting and a storage cap in the Presto /query route. Inserts up to MAX_PRESTO_SEARCH_RESULTS rows into MongoDB, updates metadata with total results after each chunk, and enhances logging. Adds MAX_PRESTO_SEARCH_RESULTS constant in typings.

Changes

Cohort / File(s) Summary
Presto search query flow
components/webui/server/src/routes/api/presto-search/index.ts
Adds totalResultsCount/storedResultsCount, enforces MAX_PRESTO_SEARCH_RESULTS cap on inserts, slices chunk before MongoDB insertion, updates metadata numTotalResults per chunk, and improves logging/error handling.
Presto typings/constants
components/webui/server/src/routes/api/presto-search/typings.ts
Introduces exported constant MAX_PRESTO_SEARCH_RESULTS = 1000 with JSDoc.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Server (/query)
  participant Presto
  participant MongoDB
  participant Metadata

  Client->>Server (/query): HTTP request
  Server (/query)->>Presto: Execute query stream
  loop For each data chunk
    Presto-->>Server (/query): data[]
    Server (/query)->>Server (/query): totalResultsCount += data.length
    alt Remaining storage slots > 0
      Server (/query)->>Server (/query): dataToInsert = data.slice(0, remainingSlots)
      Server (/query)->>MongoDB: insertPrestoRowsToMongo(dataToInsert)
      MongoDB-->>Server (/query): ack/error
      Server (/query)->>Server (/query): Update storedResultsCount on success
    else No remaining slots
      Server (/query)->>Server (/query): Skip insertion
    end
    Server (/query)->>Metadata: updateOne({ numTotalResults: totalResultsCount })
    Metadata-->>Server (/query): ack/error
  end
  Server (/query)-->>Client: Streamed response/completion
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • junhaoliao
  • hoophalab
  • 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.

✨ 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 marked this pull request as ready for review August 15, 2025 14:25
@davemarco davemarco requested a review from a team as a code owner August 15, 2025 14:25
@davemarco davemarco requested a review from hoophalab August 15, 2025 14:25
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: 5

📜 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 0892a1c and 96be326.

📒 Files selected for processing (2)
  • components/webui/server/src/routes/api/presto-search/index.ts (3 hunks)
  • components/webui/server/src/routes/api/presto-search/typings.ts (1 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/server/src/routes/api/presto-search/typings.ts
  • components/webui/server/src/routes/api/presto-search/index.ts
🧬 Code Graph Analysis (1)
components/webui/server/src/routes/api/presto-search/index.ts (2)
components/webui/server/src/routes/api/presto-search/typings.ts (1)
  • MAX_PRESTO_SEARCH_RESULTS (4-4)
components/webui/server/src/routes/api/presto-search/utils.ts (1)
  • insertPrestoRowsToMongo (50-50)
⏰ 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: build (macos-15)
  • GitHub Check: lint-check (ubuntu-24.04)
🔇 Additional comments (3)
components/webui/server/src/routes/api/presto-search/typings.ts (1)

1-4: LGTM: Clear constant and docstring align with the PR goal.

The constant name and documentation are self-explanatory and the value matches the UI cap.

components/webui/server/src/routes/api/presto-search/index.ts (2)

18-18: Import looks correct and consistent with NodeNext/ESM .js extensions.

Matches existing import style in this module. No issues spotted.


65-67: Counters are well-scoped for tracking totals vs stored counts.

The separation between totalResultsCount and storedResultsCount is clear and fits the PR intent.

hoophalab
hoophalab previously approved these changes Aug 15, 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.

Clean and nice change.

Validations:

  1. run sql queries that return more than 1000 rows
  2. only the first 1000 rows displayed in the table

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.

sorry I didn't think it carefully, but there is one nitpick:

Can we remove storedResultsCount and only use totalResultsCount? I guess this logic is cleaner?

Comment on lines +94 to +98
if (storedResultsCount < MAX_PRESTO_SEARCH_RESULTS) {
const remainingSlots =
MAX_PRESTO_SEARCH_RESULTS - storedResultsCount;
const dataToInsert = data.slice(0, remainingSlots);

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (storedResultsCount < MAX_PRESTO_SEARCH_RESULTS) {
const remainingSlots =
MAX_PRESTO_SEARCH_RESULTS - storedResultsCount;
const dataToInsert = data.slice(0, remainingSlots);
if (totalResultsCount < MAX_PRESTO_SEARCH_RESULTS) {
const remainingSlots =
MAX_PRESTO_SEARCH_RESULTS - totalResultsCount;
const dataToInsert = data.slice(0, remainingSlots);

// TODO: Error, and success handlers are dummy implementations
// and will be replaced with proper implementations.
data: (_, data, columns) => {
totalResultsCount += data.length;
Copy link
Contributor

@hoophalab hoophalab Aug 15, 2025

Choose a reason for hiding this comment

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

move this after the insertion of data and before the update of metadata


let searchJobId: string;
let totalResultsCount = 0;
let storedResultsCount = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

remove storedResultsCount

@hoophalab hoophalab dismissed their stale review August 15, 2025 18:26

nitpick

@davemarco
Copy link
Contributor Author

@hoophalab - I see ur point here but i am slightly worried about moving totalResultsCount += data.length; after the insertion of data. If we ever add an await into InsertPrestoRows, its possible the data callback gets called again and we might have a double insert.

@hoophalab
Copy link
Contributor

@hoophalab - I see ur point here but i am slightly worried about moving totalResultsCount += data.length; after the insertion of data. If we ever add an await into InsertPrestoRows, its possible the data callback gets called again and we might have a double insert.

sure let's keep it as-is then

@kirkrodrigues kirkrodrigues changed the title feat(webui): Limit search results in results cache to 1000 entries. feat(webui): Store only 1000 search results in the results cache for Presto queries. Aug 15, 2025
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.

@hoophalab hoophalab merged commit e087603 into y-scope:main Aug 15, 2025
7 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.

3 participants