Skip to content

Decouple project runners queuing query from projects table

Description

In #340499 (closed) we've reviewed the current state of queuing queries and discovered that we still need to decouple project runners query from the projects table:

SELECT "ci_pending_builds".*
FROM "ci_pending_builds"
WHERE "ci_pending_builds"."project_id" IN
    (SELECT "projects"."id"
     FROM "projects"
     INNER JOIN "ci_runner_projects" ON "projects"."id" = "ci_runner_projects"."project_id"
     LEFT JOIN project_features ON projects.id = project_features.project_id
     WHERE "ci_runner_projects"."runner_id" = 8
       AND "projects"."pending_delete" = FALSE
       AND ("project_features"."builds_access_level" > 0
            OR "project_features"."builds_access_level" IS NULL))
  AND (tag_ids = {})
ORDER BY build_id ASC;

Proposal

We should be able to use ci_runner_projects table directly, and avoid pushing a build to the queue if a project is pending delete or builds are disabled in it.

Edited by Max Orefice