Skip to content

Conversation

@fsargent
Copy link
Contributor

@fsargent fsargent commented Oct 1, 2025

Example: 20 items on a page, total shows 6024 (total dependencies in the org).
The docs now match the implementation.
https://snyksec.atlassian.net/browse/TRACKER-958

@fsargent fsargent requested review from a team as code owners October 1, 2025 16:22
@fsargent fsargent changed the title fix: total now reflects the total count across the organization matching the filters, not the current page. fix: v1 dependencies - total now reflects the total count across the organization matching the filters, not the current page. Oct 1, 2025
@fsargent fsargent force-pushed the fix/TRACKER-958-total-in-dependencies-api-endpoint-response-does-not-respect-filter branch from 434dbbb to 71faa8c Compare October 1, 2025 16:27
…ing the filters, not the current page.

Example: 20 items on a page, total shows 6024 (total dependencies in the org).
The docs now match the implementation.
@fsargent fsargent force-pushed the fix/TRACKER-958-total-in-dependencies-api-endpoint-response-does-not-respect-filter branch from 71faa8c to c071498 Compare October 1, 2025 16:28
@snyk-io
Copy link

snyk-io bot commented Oct 1, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

code/snyk check is complete. No issues have been found. (View Details)

total:
type: number
description: The number of results returned
description: The total number of dependencies in the organization matching the applied filters
Copy link
Contributor

Choose a reason for hiding this comment

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

Please provide some supporting documentation for this. (code snippets, example API calls with/without filters)

Copy link
Contributor Author

@fsargent fsargent Oct 2, 2025

Choose a reason for hiding this comment

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

Code Analysis

In registry/src/web/routes/api/v1/external/org/dependencies.ts:
Line 273: total: count, — the count variable is returned as total
Lines 230-249: count comes from Projects.getProjectsAndDependencies()

In dependencies.ts (lines 188-199): count is computed by ProjectSnapshotsStorage.countMonitorDependencies()

In monitor-dependencies.ts
(lines 829-834): the SQL is COUNT(DISTINCT("full")) AS "count" — a distinct count of all dependencies matching the filters


Tracing how filters are applied in the dependencies API to confirm whether total reflects them.

The total field accounts for filters

Filter flow

  1. API endpoint (dependencies.ts lines 222-229): extracts filters from the request body
  2. getProjectsAndDependencies() (line 243): passes ...usedFilters to the database layer
  3. countMonitorDependencies() (lines 188-199): receives the filters
  4. generateDependenciesWhereSQL() (lines 709-764): builds the WHERE clause from:
    • dependencies (lines 728-731)
    • licenses (lines 733-739)
    • severity (lines 747-756)
    • depStatus (lines 741-745)
    • monitorIds (lines 723-726)

SQL query

SELECT COUNT(DISTINCT("full")) AS "count" 
FROM monitor_dependencies 
WHERE ${where.query}

The where.query includes all applied filters, so the count reflects only dependencies matching those filters.

Example

  • No filters: total = 6024 (all dependencies in the org)
  • With severity filter: total = 150 (dependencies with high-severity issues)
  • With license filter: total = 50 (dependencies with specific licenses)

Documentation update

The description should be:

"The total number of dependencies in the organization matching the applied filters"

This is more accurate than "The number of results returned" because it reflects the filtered total, not the current page size.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant trying out the actual API not some AI-generated tokens

@fsargent fsargent requested a review from gergo-papp October 7, 2025 08:39
@fsargent fsargent merged commit 1673d82 into main Oct 7, 2025
9 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.

4 participants