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
aa3fcd86
Commit
aa3fcd86
authored
Jun 16, 2020
by
Terri Chu
Committed by
Dylan Griffith
Jun 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Improve performance of Search API (Advanced): users scope"
parent
d6628cd7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
7 deletions
+23
-7
app/services/search_service.rb
app/services/search_service.rb
+11
-6
changelogs/unreleased/215711-improve-performance-of-search-api-advanced-users-scope.yml
...mprove-performance-of-search-api-advanced-users-scope.yml
+5
-0
lib/gitlab/pagination/offset_pagination.rb
lib/gitlab/pagination/offset_pagination.rb
+7
-1
No files found.
app/services/search_service.rb
View file @
aa3fcd86
...
...
@@ -82,16 +82,21 @@ class SearchService
end
def
redact_unauthorized_results
(
results_collection
)
results
=
results_collection
.
to_a
permitted_results
=
results
.
select
{
|
object
|
visible_result?
(
object
)
}
redacted_results
=
results_collection
.
reject
{
|
object
|
visible_result?
(
object
)
}
redacted_results
=
(
results
-
permitted_results
).
each_with_object
({})
do
|
object
,
memo
|
memo
[
object
.
id
]
=
{
ability: :"read_
#{
object
.
to_ability_name
}
"
,
id:
object
.
id
,
class_name:
object
.
class
.
name
}
if
redacted_results
.
any?
redacted_log
=
redacted_results
.
each_with_object
({})
do
|
object
,
memo
|
memo
[
object
.
id
]
=
{
ability: :"read_
#{
object
.
to_ability_name
}
"
,
id:
object
.
id
,
class_name:
object
.
class
.
name
}
end
log_redacted_search_results
(
redacted_log
.
values
)
return
results_collection
.
id_not_in
(
redacted_log
.
keys
)
if
results_collection
.
is_a?
(
ActiveRecord
::
Relation
)
end
log_redacted_search_results
(
redacted_results
.
values
)
if
redacted_results
.
any?
return
results_collection
if
results_collection
.
is_a?
(
ActiveRecord
::
Relation
)
return
results_collection
.
id_not_in
(
redacted_results
.
keys
)
if
results_collection
.
is_a?
(
ActiveRecord
::
Relation
)
permitted_results
=
results_collection
-
redacted_results
Kaminari
.
paginate_array
(
permitted_results
,
...
...
changelogs/unreleased/215711-improve-performance-of-search-api-advanced-users-scope.yml
0 → 100644
View file @
aa3fcd86
---
title
:
Reduce redundant queries for Search API users scope.
merge_request
:
33795
author
:
type
:
performance
lib/gitlab/pagination/offset_pagination.rb
View file @
aa3fcd86
...
...
@@ -19,7 +19,13 @@ module Gitlab
private
def
paginate_with_limit_optimization
(
relation
)
pagination_data
=
relation
.
page
(
params
[
:page
]).
per
(
params
[
:per_page
])
# do not paginate relation if it is already paginated
pagination_data
=
if
relation
.
respond_to?
(
:current_page
)
&&
relation
.
current_page
==
params
[
:page
]
&&
relation
.
limit_value
==
params
[
:per_page
]
relation
else
relation
.
page
(
params
[
:page
]).
per
(
params
[
:per_page
])
end
return
pagination_data
unless
pagination_data
.
is_a?
(
ActiveRecord
::
Relation
)
return
pagination_data
unless
Feature
.
enabled?
(
:api_kaminari_count_with_limit
)
...
...
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