Skip to content

Exclude SBoM occurrences from inactive projects

mo khan requested to merge mokhax/432264/explore-active-dependencies into master

What does this MR do and why?

This change updates the Explore page Dependency list to exclude any dependencies that originate from projects that are archived , pending deletion or hidden.

#438729 (closed)

SELECT 
  "sbom_occurrences"."id",
  "sbom_occurrences"."created_at",
  "sbom_occurrences"."updated_at",
  "sbom_occurrences"."component_version_id",
  "sbom_occurrences"."project_id",
  "sbom_occurrences"."pipeline_id",
  "sbom_occurrences"."source_id",
  "sbom_occurrences"."commit_sha",
  "sbom_occurrences"."component_id",
  "sbom_occurrences"."uuid",
  "sbom_occurrences"."package_manager",
  "sbom_occurrences"."component_name",
  "sbom_occurrences"."input_file_path",
  "sbom_occurrences"."licenses",
  "sbom_occurrences"."highest_severity",
  "sbom_occurrences"."vulnerability_count",
  "sbom_occurrences"."source_package_id"
FROM "sbom_occurrences"
INNER JOIN "projects" ON "sbom_occurrences"."project_id" = "projects"."id"
WHERE "projects"."organization_id" = 1
  AND "projects"."archived" = FALSE
ORDER BY "sbom_occurrences"."id" ASC
LIMIT 20
OFFSET 0;
Time: 34.399 ms
  - planning: 7.250 ms
  - execution: 27.149 ms
    - I/O read: 26.740 ms
    - I/O write: 0.000 ms

Shared buffers:
  - hits: 106 (~848.00 KiB) from the buffer pool
  - reads: 5 (~40.00 KiB) from the OS file cache, including disk I/O
  - dirtied: 0
  - writes: 0

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/26172/commands/82303

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Before After
Screencast_from_2024-01-30_16-58-38 Screencast_from_2024-01-30_17-01-25

How to set up and validate locally

Before:

[15] pry(main)> Organizations::Organization.default_organization.sbom_occurrences.count
  Organizations::Organization Load (0.8ms)  SELECT "organizations".* FROM "organizations" WHERE "organizations"."id" = 1 LIMIT 1 /*application:console,db_config_name:main,console_hostname:xlg-precision,console_username:mokhax,line:/app/models/organizations/organization.rb:38:in `default_organization'*/
  Sbom::Occurrence Count (2.8ms)  SELECT COUNT(*) FROM "sbom_occurrences" INNER JOIN "projects" ON "sbom_occurrences"."project_id" = "projects"."id" WHERE "projects"."organization_id" = 1 /*application:console,db_config_name:main,console_hostname:xlg-precision,console_username:mokhax,line:(pry):15:in `__pry__'*/
=> 3057
[16] pry(main)> Sbom::Occurrence.joins(:project).where(project: { organization_id: 1, pending_delete: false, hidden: false, archived: false }).count
  Sbom::Occurrence Count (2.5ms)  SELECT COUNT(*) FROM "sbom_occurrences" INNER JOIN "projects" "project" ON "project"."id" = "sbom_occurrences"."project_id" WHERE "project"."organization_id" = 1 AND "project"."pending_delete" = FALSE AND "project"."hidden" = FALSE AND "project"."archived" = FALSE /*application:console,db_config_name:main,console_hostname:xlg-precision,console_username:mokhax,line:(pry):16:in `__pry__'*/
=> 1257

After:

[18] pry(main)> Organizations::Organization.default_organization.sbom_occurrences.count
  Organizations::Organization Load (0.4ms)  SELECT "organizations".* FROM "organizations" WHERE "organizations"."id" = 1 LIMIT 1 /*application:console,db_config_name:main,console_hostname:xlg-precision,console_username:mokhax,line:/app/models/organizations/organization.rb:38:in `default_organization'*/
  Sbom::Occurrence Count (2.1ms)  SELECT COUNT(*) FROM "sbom_occurrences" INNER JOIN "projects" ON "sbom_occurrences"."project_id" = "projects"."id" WHERE "projects"."organization_id" = 1 AND "projects"."pending_delete" = FALSE AND "projects"."archived" = FALSE AND "projects"."hidden" = FALSE /*application:console,db_config_name:main,console_hostname:xlg-precision,console_username:mokhax,line:(pry):18:in `__pry__'*/
=> 1257
[19] pry(main)> Sbom::Occurrence.joins(:project).where(project: { organization_id: 1, pending_delete: false, hidden: false, archived: false }).count
  Sbom::Occurrence Count (1.0ms)  SELECT COUNT(*) FROM "sbom_occurrences" INNER JOIN "projects" "project" ON "project"."id" = "sbom_occurrences"."project_id" WHERE "project"."organization_id" = 1 AND "project"."pending_delete" = FALSE AND "project"."hidden" = FALSE AND "project"."archived" = FALSE /*application:console,db_config_name:main,console_hostname:xlg-precision,console_username:mokhax,line:(pry):19:in `__pry__'*/
=> 1257
Edited by mo khan

Merge request reports