perf: optimize API calls with total and limit query params#1140
Merged
Conversation
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>
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds 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 limitsequenceDiagram
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 }
Sequence diagram for autocomplete queries with total disabledsequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
WithPackagesByLicenseandWithSBOMsByLicense, consider documenting (e.g., via a short code comment) thatitemsPerPage: 0is intentional and supported by the backend, since this is a non-obvious pagination configuration that might be “fixed” by future refactors. - The
totalflag usage is starting to encode behavior in multiple places; consider centralizing helper functions (e.g.,withTotalOnlyParams,listWithoutTotalParams) or a small abstraction for commonHubRequestParamspatterns 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
stanislavsemeniuk
approved these changes
Jul 3, 2026
Contributor
|
Successfully created backport PR for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WithPackagesByLicenseandWithSBOMsByLicense: these components readresult.totalto display counts but never passedtotal: trueto the server, so the count was always 0/undefined. Now requeststotal: truewithlimit=0(no items returned, only the count).SearchMenuautocomplete (4 concurrent API calls) andWhatNeedsAttentiondashboard card by explicitly passingtotal: false.Details
The API supports two performance-relevant query params:
total=false— skips the expensive count query when only items are neededlimit=0withtotal=true— returns only the count without fetching any itemsWithPackagesByLicense.tsxlimit=1, nototal(bug: count always 0)limit=0,total=trueWithSBOMsByLicense.tsxlimit=1, nototal(bug: count always 0)limit=0,total=trueSearchMenu.tsxtotalomitted (4 autocomplete queries)total=falseWhatNeedsAttention.tsxtotalomittedtotal=falseTest plan
🤖 Generated with Claude Code