Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
openproject
Service Pack
Commits
b356fb26
Verified
Commit
b356fb26
authored
5 years ago
by
Tam Le
Browse files
Options
Download
Email Patches
Plain Diff
Remove n+1 query on 'assigned' view column in SP#index
parent
653719f9
master
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/controllers/service_packs_controller.rb
+4
-0
app/controllers/service_packs_controller.rb
app/views/service_packs/index.html.erb
+1
-1
app/views/service_packs/index.html.erb
with
5 additions
and
1 deletion
+5
-1
app/controllers/service_packs_controller.rb
+
4
-
0
View file @
b356fb26
...
...
@@ -25,6 +25,10 @@ class ServicePacksController < ApplicationController
wildcard_sanitized_name
=
"%
#{
ActiveRecord
::
Base
.
send
(
:sanitize_sql_like
,
params
[
:name
],
-
'!'
)
}
%"
@service_packs
=
@service_packs
.
where
(
-
"name LIKE ?"
,
wildcard_sanitized_name
)
end
# to remove N+1 query 'EXISTS'
for_added_column
=
Assign
.
active
.
where
(
-
'service_pack_id = service_packs.id'
).
to_sql
@service_packs
=
@service_packs
.
select
(
-
'service_packs.*'
,
"(CASE WHEN EXISTS (
#{
for_added_column
}
) THEN 1 ELSE 0 END) AS assigned"
)
end
def
new
...
...
This diff is collapsed.
Click to expand it.
app/views/service_packs/index.html.erb
+
1
-
1
View file @
b356fb26
...
...
@@ -67,7 +67,7 @@
<td>
<%=
sp
.
expired_date
%>
</td>
<td>
<%=
sp
.
threshold1
%>
</td>
<td>
<%=
sp
.
threshold2
%>
</td>
<td>
<%=
(
sp
.
assigned
?
?
-
'✔'
:
-
''
).
html_safe
%>
</td>
<td>
<%=
(
sp
.
assigned
==
1
?
-
'✔'
:
-
''
).
html_safe
%>
</td>
</tr>
<%
end
%>
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help