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
b6e206b0
Commit
b6e206b0
authored
May 31, 2021
by
David Kim
Committed by
Phil Hughes
Jun 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Paginate diffs using Gitaly paths
Changelog: performance
parent
c14b941c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
13 deletions
+57
-13
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+13
-3
lib/gitlab/diff/file_collection/base.rb
lib/gitlab/diff/file_collection/base.rb
+10
-5
spec/models/merge_request_diff_spec.rb
spec/models/merge_request_diff_spec.rb
+34
-5
No files found.
app/models/merge_request_diff.rb
View file @
b6e206b0
...
...
@@ -389,11 +389,21 @@ class MergeRequestDiff < ApplicationRecord
def
diffs_in_batch
(
batch_page
,
batch_size
,
diff_options
:)
fetching_repository_diffs
(
diff_options
)
do
|
comparison
|
reorder_diff_files!
diffs_batch
=
diffs_in_batch_collection
(
batch_page
,
batch_size
,
diff_options:
diff_options
)
if
comparison
comparison
.
diffs_in_batch
(
batch_page
,
batch_size
,
diff_options:
diff_options
)
if
diff_options
[
:paths
].
blank?
&&
!
without_files?
&&
diffs_batch
.
diff_file_paths
.
present?
diff_options
.
merge!
(
paths:
diffs_batch
.
diff_file_paths
,
pagination_data:
diffs_batch
.
pagination_data
)
end
comparison
.
diffs
(
diff_options
)
else
reorder_diff_files!
diffs_in_batch_collection
(
batch_page
,
batch_size
,
diff_options:
diff_options
)
diffs_batch
end
end
end
...
...
lib/gitlab/diff/file_collection/base.rb
View file @
b6e206b0
...
...
@@ -19,6 +19,7 @@ module Gitlab
@diffable
=
diffable
@include_stats
=
diff_options
.
delete
(
:include_stats
)
@pagination_data
=
diff_options
.
delete
(
:pagination_data
)
@project
=
project
@diff_options
=
diff_options
@diff_refs
=
diff_refs
...
...
@@ -47,11 +48,7 @@ module Gitlab
end
def
pagination_data
{
current_page:
nil
,
next_page:
nil
,
total_pages:
nil
}
@pagination_data
||
empty_pagination_data
end
# This mutates `diff_files` lines.
...
...
@@ -90,6 +87,14 @@ module Gitlab
private
def
empty_pagination_data
{
current_page:
nil
,
next_page:
nil
,
total_pages:
nil
}
end
def
diff_stats_collection
strong_memoize
(
:diff_stats
)
do
next
unless
fetch_diff_stats?
...
...
spec/models/merge_request_diff_spec.rb
View file @
b6e206b0
...
...
@@ -418,8 +418,8 @@ RSpec.describe MergeRequestDiff do
shared_examples_for
'fetching full diffs'
do
it
'returns diffs from repository comparison'
do
expect_next_instance_of
(
Compare
)
do
|
comparison
|
expect
(
comparison
).
to
receive
(
:diffs
_in_batch
)
.
with
(
1
,
10
,
diff_options:
diff_options
)
expect
(
comparison
).
to
receive
(
:diffs
)
.
with
(
diff_options
)
.
and_call_original
end
...
...
@@ -448,13 +448,13 @@ RSpec.describe MergeRequestDiff do
end
it_behaves_like
'fetching full diffs'
end
context
'when diff_options include ignore_whitespace_change'
do
it_behaves_like
'fetching full diffs'
do
context
'when diff_options include ignore_whitespace_change'
do
let
(
:diff_options
)
do
{
ignore_whitespace_change:
true
}
end
it_behaves_like
'fetching full diffs'
end
end
...
...
@@ -485,6 +485,35 @@ RSpec.describe MergeRequestDiff do
'files/whitespace'
])
end
context
'when diff_options include ignore_whitespace_change'
do
let
(
:diff_options
)
do
{
ignore_whitespace_change:
true
}
end
it
'returns a Gitlab::Diff::FileCollection::Compare with paginated diffs'
do
diffs
=
diff_with_commits
.
diffs_in_batch
(
1
,
10
,
diff_options:
diff_options
)
expect
(
diffs
).
to
be_a
(
Gitlab
::
Diff
::
FileCollection
::
Compare
)
expect
(
diffs
.
diff_files
.
size
).
to
eq
10
expect
(
diffs
.
pagination_data
).
to
eq
(
current_page:
1
,
next_page:
2
,
total_pages:
2
)
end
context
'with gradual load enabled'
do
before
do
stub_feature_flags
(
diffs_gradual_load:
true
)
end
it
'returns pagination data from MergeRequestDiffBatch'
do
diffs
=
diff_with_commits
.
diffs_in_batch
(
1
,
10
,
diff_options:
diff_options
)
file_count
=
diff_with_commits
.
merge_request_diff_files
.
count
expect
(
diffs
).
to
be_a
(
Gitlab
::
Diff
::
FileCollection
::
Compare
)
expect
(
diffs
.
diff_files
.
size
).
to
eq
10
expect
(
diffs
.
pagination_data
).
to
eq
(
current_page:
nil
,
next_page:
nil
,
total_pages:
file_count
)
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