Skip to content

perf(api): batch active finding IDs on the products list - #17055

Open
tayfunozgur13 wants to merge 1 commit into
DefectDojo:devfrom
tayfunozgur13:codex/16727-batch-product-finding-ids
Open

tayfunozgur13 wants to merge 1 commit into
DefectDojo:devfrom
tayfunozgur13:codex/16727-batch-product-finding-ids

Conversation

@tayfunozgur13

Copy link
Copy Markdown

Description

The products list still runs one query per product for findings_list, even after the other relation-loading improvements in #16037. A page growing from one product to five therefore adds four queries, including for a regular member.

Load active finding IDs in one query after authorization, filtering and pagination, and let ProductSerializer use those page-local lists. Only IDs and their product IDs are selected; findings are not materialized as model instances. Preserve the current finding ordering, active-only selection and complete response arrays. Detail and write responses retain the existing fallback.

Batching applies only to the list action: delete previews also use this paginator, but contain rendered dictionaries rather than Product instances.

Related to #16727. This addresses the remaining per-product query growth. The separate proposal to cap or replace findings_list remains open; large ID arrays still produce large responses.

Test results

Added coverage for query growth as an administrator and a member, products without active findings, ID ordering across engagements, inactive findings, unchanged active false-positive behavior, authorization, filtering, pagination, empty pages and retrieve fallback. Strengthened the existing product regression to require zero query growth.

  • Before the production fix: 8 tests, 2 failures; four additional products added four queries for both users.
  • After the fix: 9 focused tests passed; query growth is zero, including products with no active findings.
  • Broader validation: 54 tests, 49 passed and 5 expected skips:
    ./run-unittest.sh --test-case 'unittests.test_api_product_prefetch unittests.test_rest_framework.ProductTest unittests.test_apiv2_list_query_scaling unittests.test_apiv2_prefetch_locations unittests.test_product_authorized_users_api_authz unittests.test_apiv2_server_error_logging'
  • ruff check --config ruff.toml . passed with the pinned Ruff 0.16.10.
  • docker compose exec -T uwsgi python manage.py check passed with existing development-environment warnings.
  • docker compose exec -T uwsgi python manage.py makemigrations --check --dry-run: no changes detected.
  • docker compose exec -T uwsgi python manage.py spectacular --fail-on-warn passed.
  • Read-only HTTP checks through the local nginx API passed for list/detail IDs and ordering, counts, ID filtering, pagination and an empty page.

No migrations, dependencies or API contract changes.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant