Skip to content

BuildFinishedWorker is slow

Based on the slow log the BuildFinishedWorker can produce SQL queries that are very slow, longer than 10 seconds.

SELECT $1 AS one 
FROM "projects" 
WHERE "projects"."namespace_id" IN (
  SELECT "namespaces"."id" FROM "namespaces" 
  WHERE (traversal_ids @> ($2))) 
AND "projects"."shared_runners_enabled" = $3 
LIMIT $4 ```

There was a [similar issue](https://gitlab.com/gitlab-org/gitlab/-/issues/331429) with `EE::Namespace#any_project_with_shared_runners_enabled?` that [was fixed](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62268).

We need to replace the `self_and_descendants` call made by `BuildFinishedWorker` with a call to `self_and_descendant_ids`.