Commit 26834341 authored by Brett Walker's avatar Brett Walker

Use cached column list for members union query

When doing a UNION query against a table that has a newly
added column, if the Rails code has not yet been restarted,
there can be a mismatch of columns, resulting in the UNION
query failing. This can happen during a rolling deploy across
a fleet of servers.

This fixes one such instance.

Changelog: fixed
parent 592b0107
......@@ -65,10 +65,10 @@ class Member < ApplicationRecord
scope :in_hierarchy, ->(source) do
groups = source.root_ancestor.self_and_descendants
group_members = Member.default_scoped.where(source: groups)
group_members = Member.default_scoped.where(source: groups).select(*Member.cached_column_list)
projects = source.root_ancestor.all_projects
project_members = Member.default_scoped.where(source: projects)
project_members = Member.default_scoped.where(source: projects).select(*Member.cached_column_list)
Member.default_scoped.from_union([
group_members,
......
......@@ -2104,8 +2104,8 @@ class User < ApplicationRecord
def authorized_groups_without_shared_membership
Group.from_union([
groups.select(Namespace.arel_table[Arel.star]),
authorized_projects.joins(:namespace).select(Namespace.arel_table[Arel.star])
groups.select(*Namespace.cached_column_list),
authorized_projects.joins(:namespace).select(*Namespace.cached_column_list)
])
end
......
......@@ -39,6 +39,7 @@ module Projects
GroupMember
.active_without_invites_and_requests
.with_source_id(visible_groups.self_and_ancestors.pluck_primary_key)
.select(*GroupMember.cached_column_list)
end
def visible_groups
......@@ -52,11 +53,12 @@ module Projects
end
def project_members_through_ancestral_groups
project.group.present? ? project.group.members_with_parents : Member.none
members = project.group.present? ? project.group.members_with_parents : Member.none
members.select(*GroupMember.cached_column_list)
end
def individual_project_members
project.project_members
project.project_members.select(*GroupMember.cached_column_list)
end
def project_owner?
......
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