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
07e829fc
Commit
07e829fc
authored
Jul 01, 2019
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Environment scope should not reorder whole query
Rather, only reverse the ORDER clause for this relation
parent
99ac56ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
2 deletions
+9
-2
ee/app/models/concerns/has_environment_scope.rb
ee/app/models/concerns/has_environment_scope.rb
+4
-2
ee/changelogs/unreleased/fix_environment_scope_to_not_reorder.yml
...elogs/unreleased/fix_environment_scope_to_not_reorder.yml
+5
-0
No files found.
ee/app/models/concerns/has_environment_scope.rb
View file @
07e829fc
...
@@ -23,6 +23,8 @@ module HasEnvironmentScope
...
@@ -23,6 +23,8 @@ module HasEnvironmentScope
# This is equivalent to using `#last` from SQL standpoint.
# This is equivalent to using `#last` from SQL standpoint.
#
#
scope
:on_environment
,
->
(
environment_name
,
relevant_only:
false
)
do
scope
:on_environment
,
->
(
environment_name
,
relevant_only:
false
)
do
order_direction
=
relevant_only
?
'DESC'
:
'ASC'
where
=
<<~
SQL
where
=
<<~
SQL
environment_scope IN (:wildcard, :environment_name) OR
environment_scope IN (:wildcard, :environment_name) OR
:environment_name LIKE
:environment_name LIKE
...
@@ -34,7 +36,7 @@ module HasEnvironmentScope
...
@@ -34,7 +36,7 @@ module HasEnvironmentScope
WHEN %{wildcard} THEN 0
WHEN %{wildcard} THEN 0
WHEN %{environment_name} THEN 2
WHEN %{environment_name} THEN 2
ELSE 1
ELSE 1
END
END
#{
order_direction
}
SQL
SQL
values
=
{
values
=
{
...
@@ -69,7 +71,7 @@ module HasEnvironmentScope
...
@@ -69,7 +71,7 @@ module HasEnvironmentScope
relation
=
where
(
where
,
values
)
relation
=
where
(
where
,
values
)
.
order
(
order
%
quoted_values
)
# `order` cannot escape for us!
.
order
(
order
%
quoted_values
)
# `order` cannot escape for us!
relation
=
relation
.
reverse_order
.
limit
(
1
)
if
relevant_only
relation
=
relation
.
limit
(
1
)
if
relevant_only
relation
relation
end
end
...
...
ee/changelogs/unreleased/fix_environment_scope_to_not_reorder.yml
0 → 100644
View file @
07e829fc
---
title
:
Fix on_environment scope to not re-order whole query
merge_request
:
14481
author
:
type
:
fixed
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