Skip to content

perf: optimize API calls with total and limit query params [Backport release/0.5.z]#1141

Merged
ctron merged 1 commit into
release/0.5.zfrom
backport-1140-to-release/0.5.z
Jul 3, 2026
Merged

perf: optimize API calls with total and limit query params [Backport release/0.5.z]#1141
ctron merged 1 commit into
release/0.5.zfrom
backport-1140-to-release/0.5.z

Conversation

@trustify-ci-bot

@trustify-ci-bot trustify-ci-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

Backport of #1140 to release/0.5.z.

Summary by Sourcery

Optimize client API requests by adjusting pagination and total-count flags for license- and search-related queries.

Enhancements:

  • Avoid fetching items when only total counts by license are needed by setting itemsPerPage to zero and requesting totals explicitly.
  • Disable unnecessary total count calculations in search and home views to reduce API overhead.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
(cherry picked from commit 681d588)
@sourcery-ai

sourcery-ai Bot commented Jul 3, 2026

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

Reviewer's Guide

Adjust client-side hub API requests to control server-side total counting and limit per-page items for performance, especially when only counts are needed.

Sequence diagram for optimized total-only package fetch

sequenceDiagram
  actor WithPackagesByLicense
  participant useFetchPackages
  participant HubAPI
  participant children

  WithPackagesByLicense->>useFetchPackages: useFetchPackages(filters, page_itemsPerPage_0, total_true)
  useFetchPackages->>HubAPI: GET_packages(total_true, limit_0)
  HubAPI-->>useFetchPackages: packages_response(total)
  useFetchPackages-->>WithPackagesByLicense: result(total)
  WithPackagesByLicense->>children: children(result_total, isFetching, fetchError)
Loading

File-Level Changes

Change Details Files
Optimize license-based package and SBOM queries to fetch only totals without loading any items.
  • Change pagination config for license-based package fetch to request zero items per page when only count is needed
  • Enable total counting flag on license-based package fetch to retrieve total count from backend
  • Change pagination config for license-based SBOM fetch to request zero items per page when only count is needed
  • Enable total counting flag on license-based SBOM fetch to retrieve total count from backend
client/src/app/components/WithPackagesByLicense.tsx
client/src/app/components/WithSBOMsByLicense.tsx
Explicitly disable total counting on search-related queries that only need item lists, to reduce backend overhead.
  • Add total=false to component search hub request parameters to avoid unnecessary total counting
  • Add total=false to SBOM search hub request parameters to avoid unnecessary total counting
  • Add total=false to home dashboard 'WhatNeedsAttention' hub request parameters to avoid unnecessary total counting
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:

  • Consider extracting a named constant or helper for the itemsPerPage: 0 + total: true pattern so the intent (fetch only counts) is explicit and easier to reuse without repeating magic values.
  • Since total is now being explicitly toggled between true and false in multiple places, it may be worth centralizing default hub request options (e.g., in a factory/helper) to avoid future inconsistencies in how this flag is set.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting a named constant or helper for the `itemsPerPage: 0` + `total: true` pattern so the intent (fetch only counts) is explicit and easier to reuse without repeating magic values.
- Since `total` is now being explicitly toggled between `true` and `false` in multiple places, it may be worth centralizing default hub request options (e.g., in a factory/helper) to avoid future inconsistencies in how this flag is set.

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 51.32%. Comparing base (3427e85) to head (9861d77).

Additional details and impacted files
@@              Coverage Diff               @@
##           release/0.5.z    #1141   +/-   ##
==============================================
  Coverage          51.32%   51.32%           
==============================================
  Files                256      256           
  Lines               5518     5518           
  Branches            1668     1668           
==============================================
  Hits                2832     2832           
  Misses              2421     2421           
  Partials             265      265           
Flag Coverage Δ
unit 6.56% <ø> (ø)

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 merged commit f54aa78 into release/0.5.z Jul 3, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this to Done in Trustify Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant