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
6668e7eb
Commit
6668e7eb
authored
May 14, 2020
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass limit when searching for commits
parent
e437426b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
7 deletions
+66
-7
changelogs/unreleased/216908-pass-limit-and-offset-when-searching-for-commits.yml
...6908-pass-limit-and-offset-when-searching-for-commits.yml
+5
-0
lib/gitlab/project_search_results.rb
lib/gitlab/project_search_results.rb
+13
-7
spec/lib/gitlab/project_search_results_spec.rb
spec/lib/gitlab/project_search_results_spec.rb
+48
-0
No files found.
changelogs/unreleased/216908-pass-limit-and-offset-when-searching-for-commits.yml
0 → 100644
View file @
6668e7eb
---
title
:
Improve performance of commit search by limiting the number of results requested
merge_request
:
32260
author
:
type
:
performance
lib/gitlab/project_search_results.rb
View file @
6668e7eb
...
@@ -20,7 +20,7 @@ module Gitlab
...
@@ -20,7 +20,7 @@ module Gitlab
when
'wiki_blobs'
when
'wiki_blobs'
paginated_wiki_blobs
(
wiki_blobs
(
limit:
limit_up_to_page
(
page
,
per_page
)),
page
,
per_page
)
paginated_wiki_blobs
(
wiki_blobs
(
limit:
limit_up_to_page
(
page
,
per_page
)),
page
,
per_page
)
when
'commits'
when
'commits'
Kaminari
.
paginate_array
(
commits
).
page
(
page
).
per
(
per_page
)
paginated_commits
(
page
,
per_page
)
when
'users'
when
'users'
users
.
page
(
page
).
per
(
per_page
)
users
.
page
(
page
).
per
(
per_page
)
else
else
...
@@ -86,6 +86,12 @@ module Gitlab
...
@@ -86,6 +86,12 @@ module Gitlab
private
private
def
paginated_commits
(
page
,
per_page
)
results
=
commits
(
limit:
limit_up_to_page
(
page
,
per_page
))
Kaminari
.
paginate_array
(
results
).
page
(
page
).
per
(
per_page
)
end
def
paginated_blobs
(
blobs
,
page
,
per_page
)
def
paginated_blobs
(
blobs
,
page
,
per_page
)
results
=
Kaminari
.
paginate_array
(
blobs
).
page
(
page
).
per
(
per_page
)
results
=
Kaminari
.
paginate_array
(
blobs
).
page
(
page
).
per
(
per_page
)
...
@@ -139,21 +145,21 @@ module Gitlab
...
@@ -139,21 +145,21 @@ module Gitlab
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
def
commits
def
commits
(
limit:
count_limit
)
@commits
||=
find_commits
(
query
)
@commits
||=
find_commits
(
query
,
limit:
limit
)
end
end
def
find_commits
(
query
)
def
find_commits
(
query
,
limit
:
)
return
[]
unless
Ability
.
allowed?
(
@current_user
,
:download_code
,
@project
)
return
[]
unless
Ability
.
allowed?
(
@current_user
,
:download_code
,
@project
)
commits
=
find_commits_by_message
(
query
)
commits
=
find_commits_by_message
(
query
,
limit:
limit
)
commit_by_sha
=
find_commit_by_sha
(
query
)
commit_by_sha
=
find_commit_by_sha
(
query
)
commits
|=
[
commit_by_sha
]
if
commit_by_sha
commits
|=
[
commit_by_sha
]
if
commit_by_sha
commits
commits
end
end
def
find_commits_by_message
(
query
)
def
find_commits_by_message
(
query
,
limit
:
)
project
.
repository
.
find_commits_by_message
(
query
)
project
.
repository
.
find_commits_by_message
(
query
,
nil
,
nil
,
limit
)
end
end
def
find_commit_by_sha
(
query
)
def
find_commit_by_sha
(
query
)
...
...
spec/lib/gitlab/project_search_results_spec.rb
View file @
6668e7eb
...
@@ -452,6 +452,54 @@ describe Gitlab::ProjectSearchResults do
...
@@ -452,6 +452,54 @@ describe Gitlab::ProjectSearchResults do
end
end
describe
'commit search'
do
describe
'commit search'
do
context
'pagination'
do
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
it
'returns the correct results for each page'
do
expect
(
results_page
(
1
)).
to
contain_exactly
(
commit
(
'b83d6e391c22777fca1ed3012fce84f633d7fed0'
))
expect
(
results_page
(
2
)).
to
contain_exactly
(
commit
(
'498214de67004b1da3d820901307bed2a68a8ef6'
))
expect
(
results_page
(
3
)).
to
contain_exactly
(
commit
(
'1b12f15a11fc6e62177bef08f47bc7b5ce50b141'
))
end
it
'returns the correct number of pages'
do
expect
(
results_page
(
1
).
total_pages
).
to
eq
(
project
.
repository
.
commit_count
)
end
context
'limiting requested commits'
do
context
'on page 1'
do
it
"limits to
#{
described_class
::
COUNT_LIMIT
}
"
do
expect
(
project
.
repository
)
.
to
receive
(
:find_commits_by_message
)
.
with
(
anything
,
anything
,
anything
,
described_class
::
COUNT_LIMIT
)
.
and_call_original
results_page
(
1
)
end
end
context
'on subsequent pages'
do
it
"limits to
#{
described_class
::
COUNT_LIMIT
}
plus page offset"
do
expect
(
project
.
repository
)
.
to
receive
(
:find_commits_by_message
)
.
with
(
anything
,
anything
,
anything
,
described_class
::
COUNT_LIMIT
+
1
)
.
and_call_original
results_page
(
2
)
end
end
end
def
results_page
(
page
)
described_class
.
new
(
user
,
project
,
'.'
).
objects
(
'commits'
,
per_page:
1
,
page:
page
)
end
def
commit
(
hash
)
project
.
repository
.
commit
(
hash
)
end
end
context
'by commit message'
do
context
'by commit message'
do
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
let
(
:commit
)
{
project
.
repository
.
commit
(
'59e29889be61e6e0e5e223bfa9ac2721d31605b8'
)
}
let
(
:commit
)
{
project
.
repository
.
commit
(
'59e29889be61e6e0e5e223bfa9ac2721d31605b8'
)
}
...
...
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