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
57bb697c
Commit
57bb697c
authored
May 05, 2021
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable snippets to use reference filter cache
parent
a012be9c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
+34
-2
lib/banzai/filter/references/snippet_reference_filter.rb
lib/banzai/filter/references/snippet_reference_filter.rb
+6
-2
spec/lib/banzai/filter/references/reference_cache_spec.rb
spec/lib/banzai/filter/references/reference_cache_spec.rb
+1
-0
spec/lib/banzai/filter/references/snippet_reference_filter_spec.rb
...banzai/filter/references/snippet_reference_filter_spec.rb
+27
-0
No files found.
lib/banzai/filter/references/snippet_reference_filter.rb
View file @
57bb697c
...
...
@@ -11,10 +11,14 @@ module Banzai
self
.
reference_type
=
:snippet
self
.
object_class
=
Snippet
def
find_object
(
project
,
id
)
def
parent_records
(
project
,
ids
)
return
unless
project
.
is_a?
(
Project
)
project
.
snippets
.
find_by
(
id:
id
)
project
.
snippets
.
where
(
id:
ids
.
to_a
)
end
def
find_object
(
project
,
id
)
reference_cache
.
records_per_parent
[
project
][
id
]
end
def
url_for_object
(
snippet
,
project
)
...
...
spec/lib/banzai/filter/references/reference_cache_spec.rb
View file @
57bb697c
...
...
@@ -58,6 +58,7 @@ RSpec.describe Banzai::Filter::References::ReferenceCache do
# Since this is an issue filter that is not batching issue queries
# across projects, we have to account for that.
# 1 for both projects, 1 for issues in each project == 3
# TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/330359
max_count
=
control_count
+
1
expect
do
...
...
spec/lib/banzai/filter/references/snippet_reference_filter_spec.rb
View file @
57bb697c
...
...
@@ -219,4 +219,31 @@ RSpec.describe Banzai::Filter::References::SnippetReferenceFilter do
expect
(
reference_filter
(
act
,
project:
nil
,
group:
create
(
:group
)).
to_html
).
to
eq
exp
end
end
context
'checking N+1'
do
let
(
:namespace2
)
{
create
(
:namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace2
)
}
let
(
:snippet2
)
{
create
(
:project_snippet
,
project:
project2
)
}
let
(
:reference2
)
{
"
#{
project2
.
full_path
}
$
#{
snippet2
.
id
}
"
}
it
'does not have N+1 per multiple references per project'
,
:use_sql_query_cache
do
markdown
=
"
#{
reference
}
$9999990"
control_count
=
ActiveRecord
::
QueryRecorder
.
new
(
skip_cached:
false
)
do
reference_filter
(
markdown
)
end
.
count
markdown
=
"
#{
reference
}
$9999990 $9999991 $9999992 $9999993
#{
reference2
}
something/cool$12"
# Since we're not batching snippet queries across projects,
# we have to account for that.
# 1 for both projects, 1 for snippets in each project == 3
# TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/330359
max_count
=
control_count
+
1
expect
do
reference_filter
(
markdown
)
end
.
not_to
exceed_all_query_limit
(
max_count
)
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