Fix QueryCanceled error in PersistSecurityPoliciesWorker
What does this MR do and why?
This MR replaces each_batch for getting all projects in a namespace with Gitlab::Database::NamespaceEachBatch as it timesout for namespaces with a large number of projects.
Database queries
Before
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 @> (
'{4249178}'
)
)
)
AND "projects"."id" >= 22187539
ORDER BY
"projects"."id" ASC LIMIT 1 OFFSET 1000;
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 @> (
'{4249178}'
)
)
)
AND "projects"."id" >= 22187539
AND "projects"."id" < 22981486;
After
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 @> (
'{4249178}'
)
)
)
AND "projects"."id" > 22187539
ORDER BY
"projects"."id" ASC LIMIT 1000;
References
Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
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
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
| Before | After |
|---|---|
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
Edited by Sashi Kumar Kumaresan