gitlab-org--gitlab-foss/lib/gitlab/database/read_only_relation.rb
Yorick Peterse ac702af822
Fix setting share_with_group_lock
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
2017-09-15 17:38:46 +02:00

16 lines
423 B
Ruby

module Gitlab
module Database
# Module that can be injected into a ActiveRecord::Relation to make it
# read-only.
module ReadOnlyRelation
[:delete, :delete_all, :update, :update_all].each do |method|
define_method(method) do |*args|
raise(
ActiveRecord::ReadOnlyRecord,
"This relation is marked as read-only"
)
end
end
end
end
end