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
8a7babac
Commit
8a7babac
authored
Aug 07, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
ef4d0daa
e17350be
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
21 deletions
+48
-21
changelogs/unreleased/60449-reduce-gitaly-calls-when-rendering-commits-in-md.yml
...0449-reduce-gitaly-calls-when-rendering-commits-in-md.yml
+5
-0
lib/banzai/filter/abstract_reference_filter.rb
lib/banzai/filter/abstract_reference_filter.rb
+18
-0
lib/banzai/filter/commit_reference_filter.rb
lib/banzai/filter/commit_reference_filter.rb
+12
-5
lib/banzai/filter/issuable_reference_filter.rb
lib/banzai/filter/issuable_reference_filter.rb
+2
-16
spec/lib/banzai/filter/commit_reference_filter_spec.rb
spec/lib/banzai/filter/commit_reference_filter_spec.rb
+11
-0
No files found.
changelogs/unreleased/60449-reduce-gitaly-calls-when-rendering-commits-in-md.yml
0 → 100644
View file @
8a7babac
---
title
:
Batch processing of commit refs in markdown processing
merge_request
:
31037
author
:
type
:
performance
lib/banzai/filter/abstract_reference_filter.rb
View file @
8a7babac
...
...
@@ -337,6 +337,24 @@ module Banzai
@current_project_namespace_path
||=
project
&
.
namespace
&
.
full_path
end
def
records_per_parent
@_records_per_project
||=
{}
@_records_per_project
[
object_class
.
to_s
.
underscore
]
||=
begin
hash
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
{}
}
parent_per_reference
.
each
do
|
path
,
parent
|
record_ids
=
references_per_parent
[
path
]
parent_records
(
parent
,
record_ids
).
each
do
|
record
|
hash
[
parent
][
record_identifier
(
record
)]
=
record
end
end
hash
end
end
private
def
full_project_path
(
namespace
,
project_ref
)
...
...
lib/banzai/filter/commit_reference_filter.rb
View file @
8a7babac
...
...
@@ -19,12 +19,11 @@ module Banzai
end
def
find_object
(
project
,
id
)
return
unless
project
.
is_a?
(
Project
)
return
unless
project
.
is_a?
(
Project
)
&&
project
.
valid_repo?
if
project
&&
project
.
valid_repo?
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/43894
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
{
project
.
commit
(
id
)
}
end
_
,
record
=
records_per_parent
[
project
].
detect
{
|
k
,
_v
|
Gitlab
::
Git
.
shas_eql?
(
k
,
id
)
}
record
end
def
referenced_merge_request_commit_shas
...
...
@@ -66,6 +65,14 @@ module Banzai
private
def
record_identifier
(
record
)
record
.
id
end
def
parent_records
(
parent
,
ids
)
parent
.
commits_by
(
oids:
ids
.
to_a
)
end
def
noteable
context
[
:noteable
]
end
...
...
lib/banzai/filter/issuable_reference_filter.rb
View file @
8a7babac
...
...
@@ -3,22 +3,8 @@
module
Banzai
module
Filter
class
IssuableReferenceFilter
<
AbstractReferenceFilter
def
records_per_parent
@records_per_project
||=
{}
@records_per_project
[
object_class
.
to_s
.
underscore
]
||=
begin
hash
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
{}
}
parent_per_reference
.
each
do
|
path
,
parent
|
record_ids
=
references_per_parent
[
path
]
parent_records
(
parent
,
record_ids
).
each
do
|
record
|
hash
[
parent
][
record
.
iid
.
to_i
]
=
record
end
end
hash
end
def
record_identifier
(
record
)
record
.
iid
.
to_i
end
def
find_object
(
parent
,
iid
)
...
...
spec/lib/banzai/filter/commit_reference_filter_spec.rb
View file @
8a7babac
...
...
@@ -105,6 +105,17 @@ describe Banzai::Filter::CommitReferenceFilter do
expect
(
doc
.
css
(
'a'
).
first
[
:href
]).
to
eq
(
url
)
end
context
"a doc with many (29) strings that could be SHAs"
do
let!
(
:oids
)
{
noteable
.
commits
.
collect
(
&
:id
)
}
it
'makes only a single request to Gitaly'
do
expect
(
Gitlab
::
GitalyClient
).
to
receive
(
:allow_n_plus_1_calls
).
exactly
(
0
).
times
expect
(
Gitlab
::
Git
::
Commit
).
to
receive
(
:batch_by_oid
).
once
.
and_call_original
reference_filter
(
"A big list of SHAs
#{
oids
.
join
(
", "
)
}
"
,
noteable:
noteable
)
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