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
336d3ccc
Commit
336d3ccc
authored
Aug 07, 2019
by
Kerri Miller
Committed by
Douwe Maan
Aug 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit of WIP code for consideration
Squash this commit and reword before merging..
parent
35e49d3b
Changes
5
Show 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 @
336d3ccc
---
title
:
Batch processing of commit refs in markdown processing
merge_request
:
31037
author
:
type
:
performance
lib/banzai/filter/abstract_reference_filter.rb
View file @
336d3ccc
...
@@ -337,6 +337,24 @@ module Banzai
...
@@ -337,6 +337,24 @@ module Banzai
@current_project_namespace_path
||=
project
&
.
namespace
&
.
full_path
@current_project_namespace_path
||=
project
&
.
namespace
&
.
full_path
end
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
private
def
full_project_path
(
namespace
,
project_ref
)
def
full_project_path
(
namespace
,
project_ref
)
...
...
lib/banzai/filter/commit_reference_filter.rb
View file @
336d3ccc
...
@@ -19,12 +19,11 @@ module Banzai
...
@@ -19,12 +19,11 @@ module Banzai
end
end
def
find_object
(
project
,
id
)
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?
_
,
record
=
records_per_parent
[
project
].
detect
{
|
k
,
_v
|
Gitlab
::
Git
.
shas_eql?
(
k
,
id
)
}
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/43894
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
{
project
.
commit
(
id
)
}
record
end
end
end
def
referenced_merge_request_commit_shas
def
referenced_merge_request_commit_shas
...
@@ -66,6 +65,14 @@ module Banzai
...
@@ -66,6 +65,14 @@ module Banzai
private
private
def
record_identifier
(
record
)
record
.
id
end
def
parent_records
(
parent
,
ids
)
parent
.
commits_by
(
oids:
ids
.
to_a
)
end
def
noteable
def
noteable
context
[
:noteable
]
context
[
:noteable
]
end
end
...
...
lib/banzai/filter/issuable_reference_filter.rb
View file @
336d3ccc
...
@@ -3,22 +3,8 @@
...
@@ -3,22 +3,8 @@
module
Banzai
module
Banzai
module
Filter
module
Filter
class
IssuableReferenceFilter
<
AbstractReferenceFilter
class
IssuableReferenceFilter
<
AbstractReferenceFilter
def
records_per_parent
def
record_identifier
(
record
)
@records_per_project
||=
{}
record
.
iid
.
to_i
@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
end
end
def
find_object
(
parent
,
iid
)
def
find_object
(
parent
,
iid
)
...
...
spec/lib/banzai/filter/commit_reference_filter_spec.rb
View file @
336d3ccc
...
@@ -105,6 +105,17 @@ describe Banzai::Filter::CommitReferenceFilter do
...
@@ -105,6 +105,17 @@ describe Banzai::Filter::CommitReferenceFilter do
expect
(
doc
.
css
(
'a'
).
first
[
:href
]).
to
eq
(
url
)
expect
(
doc
.
css
(
'a'
).
first
[
:href
]).
to
eq
(
url
)
end
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
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