diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-09-15 15:34:41 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-09-15 17:38:46 +0200 |
commit | ac702af8229193834baf8d3fd3a1b454b5459289 (patch) | |
tree | 34c425c3010e4119d11dd14c1b639ccc70abb7e8 /app/models/namespace.rb | |
parent | 20295b3db379f4be02521cac591feca3452a2b1c (diff) | |
download | gitlab-ce-ac702af8229193834baf8d3fd3a1b454b5459289.tar.gz |
Fix setting share_with_group_lockfix-share-with-group-lock-update
Prior to this commit running
Namespace#force_share_with_group_lock_on_descendants would result in
updating _all_ namespaces in the namespaces table, not just the
descendants. This is the result of ActiveRecord::Relation#update_all not
taking into account the CTE. To work around this we use the CTE query as
a sub-query instead of directly calling #update_all.
To prevent this from happening the relations returned by
Gitlab::GroupHierarchy are now marked as read-only, resulting in an
error being raised when methods such as #update_all are used.
Fortunately on GitLab.com our statement timeouts appear to have
prevented this query from actually doing any damage other than causing
a very large amount of dead tuples.
Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/37916
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r-- | app/models/namespace.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 4a9a23fea1f..e279d8dd8c5 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -231,6 +231,13 @@ class Namespace < ActiveRecord::Base end def force_share_with_group_lock_on_descendants - descendants.update_all(share_with_group_lock: true) + return unless Group.supports_nested_groups? + + # We can't use `descendants.update_all` since Rails will throw away the WITH + # RECURSIVE statement. We also can't use WHERE EXISTS since we can't use + # different table aliases, hence we're just using WHERE IN. Since we have a + # maximum of 20 nested groups this should be fine. + Namespace.where(id: descendants.select(:id)) + .update_all(share_with_group_lock: true) end end |