Skip to content

feat(new-webui): Limit search results to most recent 1000 entries.#999

Merged
davemarco merged 4 commits into
y-scope:mainfrom
davemarco:newsort
Jun 11, 2025
Merged

feat(new-webui): Limit search results to most recent 1000 entries.#999
davemarco merged 4 commits into
y-scope:mainfrom
davemarco:newsort

Conversation

@davemarco

@davemarco davemarco commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

Description

Per discussion, results cache can actually have >1000 entries.

PR limits search results to 1000 most recent entries. Data is still sorted client side, but we only sort 1000 recent entries.

I also added fallback to sort by mongoID when there are ties.

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

Only retrieves 1000 results.

Summary by CodeRabbit

  • New Features

    • Introduced a maximum limit of 1000 search results displayed in the search results table.
  • Enhancements

    • Search results are now sorted by timestamp in descending order, and by ID when timestamps are equal, ensuring a consistent and logical display order.

@davemarco davemarco requested a review from a team as a code owner June 11, 2025 13:52
@coderabbitai

coderabbitai Bot commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes update the search results sorting logic to order by timestamp descending and, in case of ties, by ID descending. A new constant for the maximum number of search results is introduced and used to limit query results. The relevant hook is updated to apply these sorting and limiting options.

Changes

File(s) Change Summary
.../SearchResultsTable/typings.tsx Changed default sort order for "timestamp" to descending; enhanced sorting to break ties by _id; added and exported SEARCH_MAX_NUM_RESULTS constant.
.../SearchResultsTable/useSearchResults.ts Imported SEARCH_MAX_NUM_RESULTS; updated query to sort by timestamp and _id descending and limit results to the new constant.

Possibly related PRs

Suggested reviewers

  • 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 6b15926 and e7c4f00.

📒 Files selected for processing (1)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts
🧬 Code Graph Analysis (1)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts (2)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx (1)
  • SEARCH_MAX_NUM_RESULTS (86-86)
components/log-viewer-webui/server/src/fastify-v2/routes/api/search/typings.ts (1)
  • SEARCH_MAX_NUM_RESULTS (47-47)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (macos-latest)
  • GitHub Check: lint-check (ubuntu-latest)
🔇 Additional comments (1)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts (1)

4-7: Import change looks correct

The added import cleanly pulls in the shared SEARCH_MAX_NUM_RESULTS constant and the SearchResult type; no issues spotted.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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 junhaoliao June 11, 2025 13:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e1c32b and 6b15926.

📒 Files selected for processing (2)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx (2 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx
🧬 Code Graph Analysis (2)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts (1)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx (1)
  • SEARCH_MAX_NUM_RESULTS (86-86)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx (2)
components/log-viewer-webui/client/src/typings/datetime.ts (1)
  • DATETIME_FORMAT_TEMPLATE (3-3)
components/log-viewer-webui/server/src/fastify-v2/routes/api/search/typings.ts (1)
  • SEARCH_MAX_NUM_RESULTS (47-47)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: build (macos-latest)
  • GitHub Check: lint-check (macos-latest)

Comment on lines +86 to 89
SEARCH_MAX_NUM_RESULTS,
searchResultsTableColumns,
TABLE_BOTTOM_PADDING,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Re-export order nit

Minor: exporting the new constant before the column configs would better match the declaration order above.

🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx
around lines 86 to 89, the export order is inconsistent with the declaration
order. Move the export of SEARCH_MAX_NUM_RESULTS to appear before the export of
searchResultsTableColumns and TABLE_BOTTOM_PADDING to match the order in which
they are declared above.

Comment on lines +78 to +82
/**
* The maximum number of results to retrieve for a search.
*/
const SEARCH_MAX_NUM_RESULTS = 1000;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Duplicate definition of SEARCH_MAX_NUM_RESULTS across client & server

A constant with the same value already lives in server/src/fastify-v2/routes/api/search/typings.ts. Maintaining two sources invites drift.
Recommend moving the value to a shared package (e.g., shared/consts.ts) and importing it in both places, or piping it from the server to the client via an API/ENV.

🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx
around lines 78 to 82, the constant SEARCH_MAX_NUM_RESULTS is duplicated from
the server code, risking value drift. To fix this, move the constant definition
to a shared module like shared/consts.ts, then import it in both the client and
server files. Alternatively, expose the value from the server via an API or
environment variable and consume it in the client to maintain a single source of
truth.

Comment on lines +37 to +43
const timestampDiff = a.timestamp - b.timestamp;
if (0 !== timestampDiff) {
return timestampDiff;
}

return a._id.localeCompare(b._id);
},

Copy link
Copy Markdown
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

Comparator returns ascending order; verify this aligns with intended “descend” default

defaultSortOrder is set to "descend", yet the comparator returns a.timestamp - b.timestamp, which produces an ascending result set that Ant Design will then invert to achieve descending order.
If someone later removes/changes defaultSortOrder, the implicit coupling may break. Consider returning the inverted difference to make the comparator self-contained and future-proof:

-const timestampDiff = a.timestamp - b.timestamp;
+const timestampDiff = b.timestamp - a.timestamp;

Same reasoning applies to the _id fallback:

-return a._id.localeCompare(b._id);
+return b._id.localeCompare(a._id);

This keeps the comparator’s semantics clear and avoids relying on external props for direction.


🏁 Script executed:

#!/bin/bash
# Search for defaultSortOrder occurrences across the codebase
rg -n "defaultSortOrder" -A3 -B3

echo "----"
# Search for sorter definitions in SearchResultsTable directory
rg -n "sorter" -A5 -B5 components/log-viewer-webui/client/src/pages/SearchPage/SearchResults

Length of output: 2691


Make the sorter self-contained by flipping to descending

The current comparator (a.timestamp - b.timestamp) produces an ascending sort that Ant Design then reverses due to defaultSortOrder: "descend". To avoid this implicit coupling—so changing or removing defaultSortOrder won’t silently break the order—flip both parts of the comparator to sort descending by default:

• File:
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx
• Around lines 36–43

-        sorter: (a, b) => {
-            const timestampDiff = a.timestamp - b.timestamp;
+        sorter: (a, b) => {
+            const timestampDiff = b.timestamp - a.timestamp;
             if (0 !== timestampDiff) {
                 return timestampDiff;
             }
-
-            return a._id.localeCompare(b._id);
+            return b._id.localeCompare(a._id);
         },

This change makes the comparator’s intent explicit and decoupled from the defaultSortOrder prop.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const timestampDiff = a.timestamp - b.timestamp;
if (0 !== timestampDiff) {
return timestampDiff;
}
return a._id.localeCompare(b._id);
},
sorter: (a, b) => {
const timestampDiff = b.timestamp - a.timestamp;
if (0 !== timestampDiff) {
return timestampDiff;
}
return b._id.localeCompare(a._id);
},
🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx
around lines 36 to 43, the comparator currently returns ascending order by
subtracting timestamps (a.timestamp - b.timestamp) and using localeCompare on
_id, which relies on the external defaultSortOrder "descend" to invert the
order. To make the comparator self-contained and explicitly descending, invert
the subtraction to (b.timestamp - a.timestamp) and reverse the localeCompare to
b._id.localeCompare(a._id). This ensures the comparator inherently sorts in
descending order without depending on external props.

Comment on lines +26 to +40
// Retrieve 1k most recent results.
const options = {
sort: [
[
"timestamp",
"desc",
],
[
"id",
"desc",
],
],
limit: SEARCH_MAX_NUM_RESULTS,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Possible micro-optimisation: build options outside cursor factory

options is constant; creating the object on every invocation of the factory is unnecessary. Hoist it above the callback to avoid needless allocations.

const BASE_SEARCH_OPTIONS = {
    sort: [
        ["timestamp", "desc"],
        ["_id", "desc"],
    ],
    limit: SEARCH_MAX_NUM_RESULTS,
};

...

const searchResultsCursor = useCursor<SearchResult>(
    () => {
        if (searchJobId === SEARCH_STATE_DEFAULT.searchJobId) {
            return null;
        }
        const collection = new MongoCollectionSocket(searchJobId.toString());
        return collection.find({}, BASE_SEARCH_OPTIONS);
    },
    [searchJobId]
);
🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts
around lines 26 to 40, the options object used for sorting and limiting search
results is recreated on every invocation of the cursor factory, causing
unnecessary allocations. To fix this, move the options object outside the
factory function and define it as a constant at the module level. Then,
reference this constant inside the factory to avoid rebuilding the object
repeatedly.

junhaoliao
junhaoliao previously approved these changes Jun 11, 2025

@junhaoliao junhaoliao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the PR title, how about:

feat(new-webui): Limit search results to most recent 1000 entries.

@davemarco davemarco changed the title feat(new-webui): Limit search results to 1k entries. feat(new-webui): Limit search results to most recent 1000 entries. Jun 11, 2025
@davemarco davemarco merged commit e90fe05 into y-scope:main Jun 11, 2025
8 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.

2 participants