Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
42ef96b7
Commit
42ef96b7
authored
Jul 19, 2021
by
Doug Stull
Committed by
Alex Ives
Jul 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enumerate columns to address db query cache issues on column change
parent
80bea93f
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
4 deletions
+16
-4
app/finders/members_finder.rb
app/finders/members_finder.rb
+4
-1
app/models/members/group_member.rb
app/models/members/group_member.rb
+2
-0
app/services/jira_import/users_mapper_service.rb
app/services/jira_import/users_mapper_service.rb
+1
-1
config/initializers/active_record_build_select.rb
config/initializers/active_record_build_select.rb
+6
-0
ee/app/services/ee/boards/lists/create_service.rb
ee/app/services/ee/boards/lists/create_service.rb
+2
-2
ee/lib/ee/gitlab/background_migration/remove_inaccessible_epic_todos.rb
...ab/background_migration/remove_inaccessible_epic_todos.rb
+1
-0
No files found.
app/finders/members_finder.rb
View file @
42ef96b7
...
@@ -83,7 +83,10 @@ class MembersFinder
...
@@ -83,7 +83,10 @@ class MembersFinder
union
=
Gitlab
::
SQL
::
Union
.
new
(
union_members
,
remove_duplicates:
false
)
# rubocop: disable Gitlab/Union
union
=
Gitlab
::
SQL
::
Union
.
new
(
union_members
,
remove_duplicates:
false
)
# rubocop: disable Gitlab/Union
sql
=
distinct_on
(
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
end
def
distinct_on
(
union
)
def
distinct_on
(
union
)
...
...
app/models/members/group_member.rb
View file @
42ef96b7
...
@@ -28,6 +28,8 @@ class GroupMember < Member
...
@@ -28,6 +28,8 @@ class GroupMember < Member
attr_accessor
:last_owner
,
:last_blocked_owner
attr_accessor
:last_owner
,
:last_blocked_owner
self
.
enumerate_columns_in_select_statements
=
true
def
self
.
access_level_roles
def
self
.
access_level_roles
Gitlab
::
Access
.
options_with_owner
Gitlab
::
Access
.
options_with_owner
end
end
...
...
app/services/jira_import/users_mapper_service.rb
View file @
42ef96b7
...
@@ -77,7 +77,7 @@ module JiraImport
...
@@ -77,7 +77,7 @@ module JiraImport
end
end
def
project_member_ids
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
.
re
select
(
:user_id
)
end
end
end
end
end
end
config/initializers/active_record_build_select.rb
View file @
42ef96b7
...
@@ -9,6 +9,10 @@
...
@@ -9,6 +9,10 @@
# statement cache. If a different migration is then run and one of these columns is
# statement cache. If a different migration is then run and one of these columns is
# removed in the meantime, the query is invalid.
# removed in the meantime, the query is invalid.
ActiveRecord
::
Base
.
class_eval
do
class_attribute
:enumerate_columns_in_select_statements
end
module
ActiveRecord
module
ActiveRecord
module
QueryMethods
module
QueryMethods
private
private
...
@@ -16,6 +20,8 @@ module ActiveRecord
...
@@ -16,6 +20,8 @@ module ActiveRecord
def
build_select
(
arel
)
def
build_select
(
arel
)
if
select_values
.
any?
if
select_values
.
any?
arel
.
project
(
*
arel_columns
(
select_values
.
uniq
))
arel
.
project
(
*
arel_columns
(
select_values
.
uniq
))
elsif
klass
.
enumerate_columns_in_select_statements
arel
.
project
(
*
klass
.
column_names
.
map
{
|
field
|
table
[
field
]
})
else
else
arel
.
project
(
@klass
.
arel_table
[
Arel
.
star
])
arel
.
project
(
@klass
.
arel_table
[
Arel
.
star
])
end
end
...
...
ee/app/services/ee/boards/lists/create_service.rb
View file @
42ef96b7
...
@@ -89,8 +89,8 @@ module EE
...
@@ -89,8 +89,8 @@ module EE
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
find_user
(
board
)
def
find_user
(
board
)
user_ids
=
user_finder
(
board
).
execute
.
select
(
:user_id
)
user_ids
=
user_finder
(
board
).
execute
.
re
select
(
:user_id
)
::
User
.
where
(
id:
user_ids
).
find_by
(
id:
params
[
'assignee_id'
])
::
User
.
id_in
(
user_ids
).
find_by
(
id:
params
[
'assignee_id'
])
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
...
...
ee/lib/ee/gitlab/background_migration/remove_inaccessible_epic_todos.rb
View file @
42ef96b7
...
@@ -19,6 +19,7 @@ module EE
...
@@ -19,6 +19,7 @@ module EE
include
FromUnion
include
FromUnion
self
.
inheritance_column
=
:_type_disabled
self
.
inheritance_column
=
:_type_disabled
self
.
enumerate_columns_in_select_statements
=
true
end
end
class
GroupGroupLink
<
ActiveRecord
::
Base
class
GroupGroupLink
<
ActiveRecord
::
Base
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment