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
007eae72
Commit
007eae72
authored
Dec 24, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix N+1 in Dashboard::SnippetsController#index
parent
9d7c81ee
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
0 deletions
+26
-0
app/controllers/dashboard/snippets_controller.rb
app/controllers/dashboard/snippets_controller.rb
+1
-0
app/models/snippet.rb
app/models/snippet.rb
+1
-0
changelogs/unreleased/fj-fix-n-plus-one-in-dashboard-snippets.yml
...gs/unreleased/fj-fix-n-plus-one-in-dashboard-snippets.yml
+5
-0
spec/controllers/dashboard/snippets_controller_spec.rb
spec/controllers/dashboard/snippets_controller_spec.rb
+19
-0
No files found.
app/controllers/dashboard/snippets_controller.rb
View file @
007eae72
...
...
@@ -18,6 +18,7 @@ class Dashboard::SnippetsController < Dashboard::ApplicationController
.
execute
.
page
(
params
[
:page
])
.
inc_author
.
inc_projects_namespace_route
return
if
redirect_out_of_range
(
@snippets
)
...
...
app/models/snippet.rb
View file @
007eae72
...
...
@@ -83,6 +83,7 @@ class Snippet < ApplicationRecord
scope
:inc_author
,
->
{
includes
(
:author
)
}
scope
:inc_relations_for_view
,
->
{
includes
(
author: :status
)
}
scope
:with_statistics
,
->
{
joins
(
:statistics
)
}
scope
:inc_projects_namespace_route
,
->
{
includes
(
project:
[
:route
,
:namespace
])
}
attr_mentionable
:description
...
...
changelogs/unreleased/fj-fix-n-plus-one-in-dashboard-snippets.yml
0 → 100644
View file @
007eae72
---
title
:
Fix N+1 when rendering snippets in the dashboard
merge_request
:
50569
author
:
type
:
performance
spec/controllers/dashboard/snippets_controller_spec.rb
View file @
007eae72
...
...
@@ -28,5 +28,24 @@ RSpec.describe Dashboard::SnippetsController do
end
it_behaves_like
'snippets sort order'
context
'when views are rendered'
do
render_views
it
'avoids N+1 database queries'
do
# Warming call to load everything non snippet related
get
(
:index
)
project
=
create
(
:project
,
namespace:
user
.
namespace
)
create
(
:project_snippet
,
project:
project
,
author:
user
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
get
(
:index
)
}.
count
project
=
create
(
:project
,
namespace:
user
.
namespace
)
create
(
:project_snippet
,
project:
project
,
author:
user
)
expect
{
get
(
:index
)
}.
not_to
exceed_query_limit
(
control_count
)
end
end
end
end
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