Skip to content

perf: optimize API calls with total and limit query params#1140

Merged
ctron merged 1 commit into
guacsec:mainfrom
ctron:fix/optimize-total-and-limit-params
Jul 3, 2026
Merged

perf: optimize API calls with total and limit query params#1140
ctron merged 1 commit into
guacsec:mainfrom
ctron:fix/optimize-total-and-limit-params

Conversation

@ctron

@ctron ctron commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix bug in WithPackagesByLicense and WithSBOMsByLicense: these components read result.total to display counts but never passed total: true to the server, so the count was always 0/undefined. Now requests total: true with limit=0 (no items returned, only the count).
  • Skip unnecessary total computation in SearchMenu autocomplete (4 concurrent API calls) and WhatNeedsAttention dashboard card by explicitly passing total: false.

Details

The API supports two performance-relevant query params:

  • total=false — skips the expensive count query when only items are needed
  • limit=0 with total=true — returns only the count without fetching any items
File Before After
WithPackagesByLicense.tsx limit=1, no total (bug: count always 0) limit=0, total=true
WithSBOMsByLicense.tsx limit=1, no total (bug: count always 0) limit=0, total=true
SearchMenu.tsx total omitted (4 autocomplete queries) total=false
WhatNeedsAttention.tsx total omitted total=false

Test plan

  • Verify license list page shows correct package and SBOM counts per license
  • Verify search autocomplete still works and shows suggestions
  • Verify home dashboard "Highest vulnerabilities" card renders correctly
  • Verify home dashboard portfolio metrics (total SBOMs/Advisories) still display

🤖 Generated with Claude Code

Fix WithPackagesByLicense and WithSBOMsByLicense which read result.total
but never requested it from the server (total was always 0). Use limit=0
since only the count is needed, not the items themselves.

Skip unnecessary total count computation in SearchMenu autocomplete and
WhatNeedsAttention dashboard card by explicitly passing total=false.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds explicit total/limit query parameter usage to fix license count bugs and avoid unnecessary total computations, using count-only queries for license-based components and disabling totals for autocomplete and dashboard queries.

Sequence diagram for count-only license queries with total and limit

sequenceDiagram
  participant WithPackagesByLicense
  participant useFetchPackages
  participant PackagesAPI

  WithPackagesByLicense->>useFetchPackages: useFetchPackages({ filters, page:{ itemsPerPage:0, pageNumber:1 }, total:true })
  useFetchPackages->>PackagesAPI: GET /packages?total=true&limit=0
  PackagesAPI-->>useFetchPackages: { total }
  useFetchPackages-->>WithPackagesByLicense: { result.total, isFetching, fetchError }
Loading

Sequence diagram for autocomplete queries with total disabled

sequenceDiagram
  participant SearchMenu
  participant useAllEntities
  participant HubAPI

  SearchMenu->>useAllEntities: useAllEntities(filterText, disableSearch)
  useAllEntities->>HubAPI: GET /entities?total=false&limit=5
  HubAPI-->>useAllEntities: { items }
  useAllEntities-->>SearchMenu: suggestions
Loading

File-Level Changes

Change Details Files
Ensure license-based package/SBOM components request only totals (no items) so displayed counts are correct without extra data fetching.
  • Update package-by-license fetch to request itemsPerPage=0 so no items are returned
  • Enable total=true on package-by-license queries so result.total is populated
  • Update SBOMs-by-license fetch to request itemsPerPage=0 so no items are returned
  • Enable total=true on SBOMs-by-license queries so result.total is populated
client/src/app/components/WithPackagesByLicense.tsx
client/src/app/components/WithSBOMsByLicense.tsx
Optimize UI queries that don't require total counts by explicitly disabling total computations.
  • Set total=false on search autocomplete package queries to avoid count queries
  • Set total=false on search autocomplete SBOM queries to avoid count queries
  • Set total=false on WhatNeedsAttention dashboard requests to avoid count queries
client/src/app/pages/search/components/SearchMenu.tsx
client/src/app/pages/home/components/WhatNeedsAttention.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Hey - I've left some high level feedback:

  • In WithPackagesByLicense and WithSBOMsByLicense, consider documenting (e.g., via a short code comment) that itemsPerPage: 0 is intentional and supported by the backend, since this is a non-obvious pagination configuration that might be “fixed” by future refactors.
  • The total flag usage is starting to encode behavior in multiple places; consider centralizing helper functions (e.g., withTotalOnlyParams, listWithoutTotalParams) or a small abstraction for common HubRequestParams patterns to avoid accidental regressions or inconsistent usage in other call sites.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `WithPackagesByLicense` and `WithSBOMsByLicense`, consider documenting (e.g., via a short code comment) that `itemsPerPage: 0` is intentional and supported by the backend, since this is a non-obvious pagination configuration that might be “fixed” by future refactors.
- The `total` flag usage is starting to encode behavior in multiple places; consider centralizing helper functions (e.g., `withTotalOnlyParams`, `listWithoutTotalParams`) or a small abstraction for common `HubRequestParams` patterns to avoid accidental regressions or inconsistent usage in other call sites.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.32%. Comparing base (2e45be3) to head (65aaf6a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1140      +/-   ##
==========================================
+ Coverage   53.07%   53.32%   +0.25%     
==========================================
  Files         270      270              
  Lines        5879     5879              
  Branches     1842     1842              
==========================================
+ Hits         3120     3135      +15     
+ Misses       2455     2443      -12     
+ Partials      304      301       -3     
Flag Coverage Δ
e2e 71.01% <ø> (+0.34%) ⬆️
unit 7.01% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ctron ctron added the backport release/0.5.z This PR should be backported to release/0.5.z branch. label Jul 3, 2026
@ctron ctron added this pull request to the merge queue Jul 3, 2026
Merged via the queue into guacsec:main with commit 681d588 Jul 3, 2026
19 checks passed
@github-project-automation github-project-automation Bot moved this to Done in Trustify Jul 3, 2026
@trustify-ci-bot

Copy link
Copy Markdown
Contributor

Successfully created backport PR for release/0.5.z:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport release/0.5.z This PR should be backported to release/0.5.z branch.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants