Update projects with incorrect data on has_external_issue_tracker and has_external_wiki
Description
This is related to #268133 (closed). Some project could have incorrect data on has_external_issue_tracker
and has_external_wiki
.
There are 4 possible scenarios that we should verify and update accordingly.
Based on the results from #database-labs (below) it seems that #268133 (closed) was not the only cause of this inconsistency.
Scenario 1
Projects where has_external_issue_tracker
is TRUE
and all the external issue trackers are inactive.
3799 affected projects (as of 5 Jan 2021) 4077 affected projects (as of 17 Feb 2021).
Click to see Rails AR
services = Service
.select('1')
.where('services.project_id = projects.id')
.where(category: 'issue_tracker')
.where(active: true)
Project
.where('NOT EXISTS (?)', services)
.where(has_external_issue_tracker: true)
.where(pending_delete: false)
.where(archived: false)
Click to see SQL query
SELECT "projects".*
FROM "projects"
WHERE (NOT EXISTS
(SELECT 1
FROM "services"
WHERE (services.project_id = projects.id)
AND "services"."category" = 'issue_tracker'
AND "services"."active" = TRUE))
AND "projects"."has_external_issue_tracker" = TRUE
AND "projects"."pending_delete" = FALSE
AND "projects"."archived" = FALSE;
Time: 3.464 min
- planning: 0.824 ms
- execution: 3.464 min
Scenario 2
Projects where has_external_issue_tracker
is FALSE
and there is at least one external issue tracker active.
201 affected projects (as of 5 Jan 2021) 340 affected projects (as of 17 Feb 2021).
Click to see Rails AR
services = Service
.select('1')
.where('services.project_id = projects.id')
.where(category: 'issue_tracker')
.where(active: true)
Project
.where('EXISTS (?)', services)
.where(has_external_issue_tracker: false)
.where(pending_delete: false)
.where(archived: false)
Click to see SQL query
SELECT "projects".*
FROM "projects"
WHERE (EXISTS
(SELECT 1
FROM "services"
WHERE (services.project_id = projects.id)
AND "services"."category" = 'issue_tracker'
AND "services"."active" = TRUE))
AND "projects"."has_external_issue_tracker" = FALSE
AND "projects"."pending_delete" = FALSE
AND "projects"."archived" = FALSE;
Time: 3.779 s
- planning: 1.033 ms
- execution: 3.778 s
Scenario 3
Projects where has_external_wiki
is TRUE
and all the external wikis are inactive.
322 affected projects (as of Jan 5 2021).
Click to see Rails AR
services = Service
.select('1')
.where('services.project_id = projects.id')
.where(type: 'ExternalWikiService')
.where(active: true)
Project
.where('NOT EXISTS (?)', services)
.where(has_external_wiki: true)
.where(pending_delete: false)
.where(archived: false)
Click to see SQL query
SELECT "projects".*
FROM "projects"
WHERE (NOT EXISTS
(SELECT 1
FROM "services"
WHERE (services.project_id = projects.id)
AND "services"."type" = 'ExternalWikiService'
AND "services"."active" = TRUE))
AND "projects"."has_external_wiki" = TRUE
AND "projects"."pending_delete" = FALSE
AND "projects"."archived" = FALSE;
Time: 1.037 min
- planning: 0.828 ms
- execution: 1.037 min
Scenario 4
Projects where has_external_wiki
is FALSE
and there is at least one external wiki active.
11 affected projects (as of Jan 5 2021).
Click to see Rails AR
services = Service
.select('1')
.where('services.project_id = projects.id')
.where(type: 'ExternalWikiService')
.where(active: true)
Project
.where('EXISTS (?)', services)
.where(has_external_wiki: false)
.where(pending_delete: false)
.where(archived: false)
Click to see SQL query
SELECT "projects".*
FROM "projects"
WHERE (EXISTS
(SELECT 1
FROM "services"
WHERE (services.project_id = projects.id)
AND "services"."type" = 'ExternalWikiService'
AND "services"."active" = TRUE))
AND "projects"."has_external_wiki" = FALSE
AND "projects"."pending_delete" = FALSE
AND "projects"."archived" = FALSE;
Time: 130.648 ms
- planning: 1.077 ms
- execution: 129.571 ms