Commit 42ef96b7 authored by Doug Stull's avatar Doug Stull Committed by Alex Ives

Enumerate columns to address db query cache issues on column change

parent 80bea93f
......@@ -83,7 +83,10 @@ class MembersFinder
union = Gitlab::SQL::Union.new(union_members, remove_duplicates: false) # rubocop: disable Gitlab/Union
sql = distinct_on(union)
Member.includes(:user).from([Arel.sql("(#{sql}) AS #{Member.table_name}")]) # rubocop: disable CodeReuse/ActiveRecord
# enumerate the columns here since we are enumerating them in the union and want to be immune to
# column caching issues when adding/removing columns
Member.select(*Member.column_names)
.includes(:user).from([Arel.sql("(#{sql}) AS #{Member.table_name}")]) # rubocop: disable CodeReuse/ActiveRecord
end
def distinct_on(union)
......
......@@ -28,6 +28,8 @@ class GroupMember < Member
attr_accessor :last_owner, :last_blocked_owner
self.enumerate_columns_in_select_statements = true
def self.access_level_roles
Gitlab::Access.options_with_owner
end
......
......@@ -77,7 +77,7 @@ module JiraImport
end
def project_member_ids
@project_member_ids ||= MembersFinder.new(project, current_user).execute.select(:user_id)
@project_member_ids ||= MembersFinder.new(project, current_user).execute.reselect(:user_id)
end
end
end
......@@ -9,6 +9,10 @@
# statement cache. If a different migration is then run and one of these columns is
# removed in the meantime, the query is invalid.
ActiveRecord::Base.class_eval do
class_attribute :enumerate_columns_in_select_statements
end
module ActiveRecord
module QueryMethods
private
......@@ -16,6 +20,8 @@ module ActiveRecord
def build_select(arel)
if select_values.any?
arel.project(*arel_columns(select_values.uniq))
elsif klass.enumerate_columns_in_select_statements
arel.project(*klass.column_names.map { |field| table[field] })
else
arel.project(@klass.arel_table[Arel.star])
end
......
......@@ -89,8 +89,8 @@ module EE
# rubocop: disable CodeReuse/ActiveRecord
def find_user(board)
user_ids = user_finder(board).execute.select(:user_id)
::User.where(id: user_ids).find_by(id: params['assignee_id'])
user_ids = user_finder(board).execute.reselect(:user_id)
::User.id_in(user_ids).find_by(id: params['assignee_id'])
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -19,6 +19,7 @@ module EE
include FromUnion
self.inheritance_column = :_type_disabled
self.enumerate_columns_in_select_statements = true
end
class GroupGroupLink < ActiveRecord::Base
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment