Skip to content

Add has_version check to project and group package finders

What does this MR do?

As per #211924 (closed), this adds the has_version check to both the project and group package finders, which was missing here but present in the previous controller actions. This will prevent packages without version numbers from being returned by the API or rendered on the frontend.

This should also fix the failure in the QA tests described in #211896 (closed).

Database

The change is adding an additional, pre-existing scope to the finders - here's how it changes the queries.

Projects

Query:

SELECT
    "packages_packages".*
FROM
    "packages_packages"
WHERE
    "packages_packages"."project_id" = 15400614
    AND ("packages_packages"."package_type" != 4
        OR "packages_packages"."name" != 'NuGet.Temporary.Package')
    AND "packages_packages"."version" IS NOT NULL
ORDER BY
    created_at DESC
LIMIT 20 OFFSET 0

Explain (from chatops):

Limit  (cost=0.42..25.32 rows=20 width=80) (actual time=1.087..1.500 rows=20 loops=1)
  Buffers: shared hit=21 read=3
  I/O Timings: read=0.864
  ->  Index Scan Backward using index_packages_packages_on_project_id_and_created_at on packages_packages  (cost=0.42..123.68 rows=99 width=80) (actual time=1.086..1.497 rows=20 loops=1)
        Index Cond: (project_id = 15400614)
        Filter: ((version IS NOT NULL) AND ((package_type <> 4) OR ((name)::text <> 'NuGet.Temporary.Package'::text)))
        Rows Removed by Filter: 1
        Buffers: shared hit=21 read=3
        I/O Timings: read=0.864
Planning time: 2.534 ms
Execution time: 1.528 ms

Visual: https://explain.depesz.com/s/oukH

Groups

Query:

SELECT
    "packages_packages".*
FROM
    "packages_packages"
WHERE
    "packages_packages"."project_id" IN (6891108)
    AND ("packages_packages"."package_type" != 4
        OR "packages_packages"."name" != 'NuGet.Temporary.Package')
    AND "packages_packages"."version" IS NOT NULL
ORDER BY
    created_at DESC
LIMIT 20 OFFSET 0

Explain (from chatops):

Limit  (cost=0.42..9.11 rows=6 width=80) (actual time=0.168..0.168 rows=0 loops=1)
  Buffers: shared hit=1 read=2
  I/O Timings: read=0.035
  ->  Index Scan Backward using index_packages_packages_on_project_id_and_created_at on packages_packages  (cost=0.42..9.11 rows=6 width=80) (actual time=0.167..0.167 rows=0 loops=1)
        Index Cond: (project_id = 6891108)
        Filter: ((version IS NOT NULL) AND ((package_type <> 4) OR ((name)::text <> 'NuGet.Temporary.Package'::text)))
        Buffers: shared hit=1 read=2
        I/O Timings: read=0.035
Planning time: 2.260 ms
Execution time: 0.188 ms

Visual: https://explain.depesz.com/s/qBvk

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

Closes #211924 (closed)

Edited by Nick Kipling

Merge request reports