Skip to content

Conversation

hoophalab
Copy link
Contributor

@hoophalab hoophalab commented Aug 12, 2025

Description

  1. add an endpoint to delete cached query result in mongo db
  2. call the endpoint when execute the second query in the client

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

  1. create a timeout to set the search state to done after clicking run
  2. the old search results is removed after initiate the second search

Summary by CodeRabbit

  • New Features

    • Added ability for users to clear previous Presto search results.
    • New searches now automatically clear any existing results for a cleaner experience.
  • Improvements

    • Reduced risk of seeing stale data by ensuring previous results are removed before new searches run.
  • Backend

    • Server-side support added to delete stored Presto search results and return appropriate success/failure responses.

@hoophalab hoophalab requested a review from a team as a code owner August 12, 2025 20:02
Copy link
Contributor

coderabbitai bot commented Aug 12, 2025

Walkthrough

Adds a client API to clear Presto query results, invokes it before submitting a new Presto query from the UI, and adds a server DELETE /api/presto-search/results route that drops the MongoDB collection for a given searchJobId.

Changes

Cohort / File(s) Summary of Changes
Client API: Presto search
components/webui/client/src/api/presto-search/index.ts
Added clearQueryResults(payload: PrestoQueryJobSchema) which issues DELETE /api/presto-search/results, logs the payload, and returns AxiosResponse<null>; updated exported symbol list to include clearQueryResults.
Client: Presto search requests flow
components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts
Added internal handlePrestoClearResults() that reads searchUiState and searchJobId, calls clearQueryResults({ searchJobId }), logs errors, and is invoked at the start of handlePrestoQuerySubmit() to clear previous results; removed the prior inline TODO.
Server API: Presto search routes
components/webui/server/src/routes/api/presto-search/index.ts
Added HTTP DELETE /results route accepting PrestoQueryJobSchema body, logs searchJobId, drops the MongoDB collection named by searchJobId, and responds with 204 No Content on success or 500 on failure.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant UI as WebUI (Presto Controls)
  participant CA as Client API (presto-search)
  participant S as Server /api/presto-search
  participant DB as MongoDB

  U->>UI: Submit Presto query
  UI->>UI: handlePrestoQuerySubmit()
  UI->>UI: handlePrestoClearResults()
  UI->>CA: clearQueryResults({ searchJobId })
  CA->>S: DELETE /results { searchJobId }
  S->>DB: dropCollection(searchJobId)
  DB-->>S: result
  S-->>CA: 204 No Content
  CA-->>UI: success
  UI->>CA: submitQuery(...)
  CA->>S: POST /submit ...
  S-->>CA: response
  CA-->>UI: response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • kirkrodrigues
  • davemarco
  • junhaoliao

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e4eb3aa and c205c06.

📒 Files selected for processing (1)
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts (4 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/SearchControls/Presto/presto-search-requests.ts
🧬 Code Graph Analysis (1)
components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts (1)
components/webui/client/src/api/presto-search/index.ts (1)
  • clearQueryResults (66-66)
⏰ 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 (ubuntu-24.04)
  • GitHub Check: lint-check (macos-15)
🔇 Additional comments (2)
components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts (2)

3-3: Import of clearQueryResults is appropriate and used

The new API is correctly imported and referenced in this module.


98-101: Good scoping: keep clear-results helper internal

Not exporting handlePrestoClearResults keeps the API surface tight and aligns with prior feedback.

✨ 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.

@hoophalab hoophalab requested a review from davemarco August 12, 2025 20: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: 7

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 759f3b0 and 9502bcf.

📒 Files selected for processing (3)
  • components/webui/client/src/api/presto-search/index.ts (1 hunks)
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts (4 hunks)
  • components/webui/server/src/routes/api/presto-search/index.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/client/src/api/presto-search/index.ts
  • components/webui/server/src/routes/api/presto-search/index.ts
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts
🧬 Code Graph Analysis (3)
components/webui/client/src/api/presto-search/index.ts (1)
components/webui/server/src/schemas/presto-search.ts (1)
  • PrestoQueryJobSchema (22-22)
components/webui/server/src/routes/api/presto-search/index.ts (3)
components/webui/client/src/api/presto-search/index.ts (1)
  • PrestoQueryJobSchema (61-61)
components/webui/server/src/schemas/presto-search.ts (1)
  • PrestoQueryJobSchema (22-22)
components/webui/server/src/schemas/error.ts (1)
  • ErrorSchema (8-8)
components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts (1)
components/webui/client/src/api/presto-search/index.ts (1)
  • clearQueryResults (66-66)
⏰ 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). (1)
  • GitHub Check: lint-check (ubuntu-24.04)

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: 1

♻️ Duplicate comments (4)
components/webui/server/src/routes/api/presto-search/index.ts (4)

184-201: Use a path param instead of a DELETE body for RESTfulness and intermediary compatibility

DELETE requests with bodies can be dropped or mishandled by proxies. Model the resource with a path param and switch schema to params.

Apply this diff:

-    fastify.delete(
-        "/results",
+    fastify.delete<{ Params: { searchJobId: string } }>(
+        "/results/:searchJobId",
         {
             schema: {
-                body: PrestoQueryJobSchema,
+                params: Type.Object({ searchJobId: Type.String() }),
                 response: {
                     [StatusCodes.NO_CONTENT]: Type.Null(),
+                    [StatusCodes.BAD_REQUEST]: ErrorSchema,
                     [StatusCodes.INTERNAL_SERVER_ERROR]: ErrorSchema,
                 },
                 tags: ["Presto Search"],
             },
         },
-        async (request, reply) => {
-            const {searchJobId} = request.body;
+        async (request, reply) => {
+            const {searchJobId} = request.params;

187-193: Add 400 BAD_REQUEST mapping to document validation failures

You’ll be adding input validation (see next comment). Reflect that in the OpenAPI response schema.

Apply this diff:

                 response: {
                     [StatusCodes.NO_CONTENT]: Type.Null(),
+                    [StatusCodes.BAD_REQUEST]: ErrorSchema,
                     [StatusCodes.INTERNAL_SERVER_ERROR]: ErrorSchema,
                 },

197-203: Validate/sanitise searchJobId to prevent arbitrary collection drops

Right now any collection name can be dropped. Allowlist to alnum/underscore/hyphen and return 400 on failure.

Apply this diff:

         async (request, reply) => {
-            const {searchJobId} = request.body;
+            const {searchJobId} = request.params;
 
             request.log.info({
                 searchJobId,
             }, "api/presto-search/results args");
 
+            // Validate collection name (allow only alnum, underscore, hyphen)
+            if (false === /^[A-Za-z0-9_-]+$/.test(searchJobId)) {
+                request.log.warn({searchJobId}, "Invalid searchJobId for results deletion");
+                reply.code(StatusCodes.BAD_REQUEST);
+                return {
+                    message: "Invalid searchJobId",
+                } as never;
+            }

203-207: Make deletion idempotent; ignore “not found” errors

Dropping a non-existent collection can throw (e.g., code 26), which should not produce a 500. Wrap and ignore NamespaceNotFound.

Apply this diff:

-            await mongoDb.collection(searchJobId).drop();
+            try {
+                const dropped = await mongoDb.collection(searchJobId).drop();
+                request.log.info({searchJobId, dropped}, "Dropped Presto results collection");
+            } catch (err: unknown) {
+                const {code, codeName} = err as {code?: number; codeName?: string};
+                // Ignore "namespace not found" (collection does not exist)
+                if (26 === code || "NamespaceNotFound" === codeName) {
+                    request.log.info({searchJobId}, "Results collection not found; nothing to delete");
+                } else {
+                    request.log.error(err, "Failed to drop Presto results collection");
+                    throw err;
+                }
+            }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9502bcf and e4eb3aa.

📒 Files selected for processing (1)
  • components/webui/server/src/routes/api/presto-search/index.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/index.ts
🧬 Code Graph Analysis (1)
components/webui/server/src/routes/api/presto-search/index.ts (3)
components/webui/client/src/api/presto-search/index.ts (1)
  • PrestoQueryJobSchema (61-61)
components/webui/server/src/schemas/presto-search.ts (1)
  • PrestoQueryJobSchema (22-22)
components/webui/server/src/schemas/error.ts (1)
  • ErrorSchema (8-8)
⏰ 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). (3)
  • GitHub Check: antlr-code-committed (macos-15)
  • GitHub Check: lint-check (ubuntu-24.04)
  • GitHub Check: lint-check (macos-15)

Copy link
Contributor

@davemarco davemarco left a comment

Choose a reason for hiding this comment

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

look great. small comments

@hoophalab hoophalab requested a review from davemarco August 13, 2025 17:36
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 @davemarco's review.

@hoophalab hoophalab merged commit c778aef into y-scope:main Aug 13, 2025
7 checks passed
@hoophalab hoophalab deleted the delete branch August 14, 2025 22:04
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