Skip to content

Add routes, controller and view to group level dependencies

What does this MR do and why?

Describe in detail what your merge request does and why.

Add routes, controller and view to group level dependencies keeping it aligned as much as possible with the project level controller. Note that the data is being fetched from a different source through.

EE: true Changelog: added

Related issue: #408837 (closed)

Migrate/Rollback

For index:

CREATE INDEX idx_sbom_occurrences_on_project_id_and_source_id ON sbom_occurrences (project_id, source_id);
$ bundle exec rails db:migrate
main: == [advisory_lock_connection] object_id: 227940, pg_backend_pid: 70376
main: == 20230605093005 AddIndexForSbomOccurrencesOnProjectIdSourceId: migrating ====
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0692s
main: -- index_exists?(:sbom_occurrences, [:project_id, :source_id], {:name=>"idx_sbom_occurrences_on_project_id_and_source_id", :algorithm=>:concurrently})
main:    -> 0.0039s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0002s
main: -- add_index(:sbom_occurrences, [:project_id, :source_id], {:name=>"idx_sbom_occurrences_on_project_id_and_source_id", :algorithm=>:concurrently})
main:    -> 0.0065s
main: -- execute("RESET statement_timeout")
main:    -> 0.0002s
main: == 20230605093005 AddIndexForSbomOccurrencesOnProjectIdSourceId: migrated (0.0918s)

main: == [advisory_lock_connection] object_id: 227940, pg_backend_pid: 70376
ci: == [advisory_lock_connection] object_id: 228180, pg_backend_pid: 70378
ci: == 20230605093005 AddIndexForSbomOccurrencesOnProjectIdSourceId: migrating ====
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0005s
ci: -- index_exists?(:sbom_occurrences, [:project_id, :source_id], {:name=>"idx_sbom_occurrences_on_project_id_and_source_id", :algorithm=>:concurrently})
ci:    -> 0.0048s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0003s
ci: -- add_index(:sbom_occurrences, [:project_id, :source_id], {:name=>"idx_sbom_occurrences_on_project_id_and_source_id", :algorithm=>:concurrently})
ci:    -> 0.0053s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0010s
ci: == 20230605093005 AddIndexForSbomOccurrencesOnProjectIdSourceId: migrated (0.0411s)

ci: == [advisory_lock_connection] object_id: 228180, pg_backend_pid: 70378

$ bundle exec rails db:rollback:main
main: == [advisory_lock_connection] object_id: 227700, pg_backend_pid: 72283
main: == 20230605093005 AddIndexForSbomOccurrencesOnProjectIdSourceId: reverting ====
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0752s
main: -- indexes(:sbom_occurrences)
main:    -> 0.0036s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0002s
main: -- remove_index(:sbom_occurrences, {:algorithm=>:concurrently, :name=>"idx_sbom_occurrences_on_project_id_and_source_id"})
main:    -> 0.0019s
main: -- execute("RESET statement_timeout")
main:    -> 0.0002s
main: == 20230605093005 AddIndexForSbomOccurrencesOnProjectIdSourceId: reverted (0.0915s)

main: == [advisory_lock_connection] object_id: 227700, pg_backend_pid: 72283

Query plan

Link to query plan: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/19174/commands/63301

SELECT 
  "sbom_occurrences".* 
FROM 
  "sbom_occurrences" 
WHERE 
  "sbom_occurrences"."project_id" IN (
    SELECT 
      "projects"."id" 
    FROM 
      "projects" 
    WHERE 
      "projects"."namespace_id" IN (
        SELECT 
          namespaces.traversal_ids[array_length(namespaces.traversal_ids, 1) ] AS id 
        FROM 
          "namespaces" 
        WHERE 
          "namespaces"."type" = 'Group' 
          AND (
            traversal_ids @ > ('{66358311}')
          )
      )
  ) 
ORDER BY 
  "sbom_occurrences"."id" ASC 
LIMIT 
  25 OFFSET 0;

Link to a query plans with filter: sbom_sources and sbom_occurrences

SELECT "sbom_sources"."id" FROM "sbom_sources" WHERE (source->'package_manager'->>'name' IN ('bundler'));

SELECT "sbom_occurrences".* FROM "sbom_occurrences" WHERE "sbom_occurrences"."project_id" IN (SELECT "projects"."id" FROM "projects" WHERE "projects"."namespace_id" IN (SELECT namespaces.traversal_ids[array_length(namespaces.traversal_ids, 1)] AS id FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND (traversal_ids @> ('{66358311}')))) AND "sbom_occurrences"."source_id" IN (9209,2527259,665036,434035,2166664,110,1313,1747555,5065,826257,826259,2072448,826556,8698,1074375,1712366,58956,49393,244431,205104,1375759,15625,123,3386,20860,3417,2073760,116,115,1271239,12152,17935,17936,5076,5374,40766,40574,1671,5723,20920,594) ORDER BY "sbom_occurrences"."id" ASC LIMIT 25 OFFSET 0;

Screenshots or screen recordings

Screenshot_2023-05-16_at_15.07.55

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Zamir Martins

Merge request reports

Loading