summaryrefslogtreecommitdiff
path: root/lib/api/projects.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-05-31 13:45:00 +0000
committerDouwe Maan <douwe@gitlab.com>2017-05-31 13:45:00 +0000
commit4ad85b22e25ab9b2d089fce7138f07c72c5fd5d6 (patch)
treec72428663addeeeef22c43ff71c6220ddfc7745b /lib/api/projects.rb
parent2c288ee1fc32703eadcf54ec73baf9199720ae35 (diff)
parent1e5506d01619780da68fc51ada58188a9070255b (diff)
downloadgitlab-ce-4ad85b22e25ab9b2d089fce7138f07c72c5fd5d6.tar.gz
Merge branch 'tc-improve-project-api-perf' into 'master'
Improve /project API performance Closes #31855 and #31937 See merge request !11666
Diffstat (limited to 'lib/api/projects.rb')
-rw-r--r--lib/api/projects.rb26
1 files changed, 12 insertions, 14 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index a827fb26b98..d00d4fe1737 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -68,20 +68,19 @@ module API
optional :import_url, type: String, desc: 'URL from which the project is imported'
end
- def present_projects(projects, options = {})
+ def present_projects(options = {})
+ projects = ProjectsFinder.new(current_user: current_user, params: project_finder_params).execute
+ projects = reorder_projects(projects)
+ projects = projects.with_statistics if params[:statistics]
+ projects = projects.with_issues_enabled if params[:with_issues_enabled]
+ projects = projects.with_merge_requests_enabled if params[:with_merge_requests_enabled]
+
options = options.reverse_merge(
- with: Entities::Project,
- current_user: current_user,
- simple: params[:simple],
- with_issues_enabled: params[:with_issues_enabled],
- with_merge_requests_enabled: params[:with_merge_requests_enabled]
+ with: current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails,
+ statistics: params[:statistics],
+ current_user: current_user
)
-
- projects = filter_projects(projects)
- projects = projects.with_statistics if options[:statistics]
- projects = projects.with_issues_enabled if options[:with_issues_enabled]
- projects = projects.with_merge_requests_enabled if options[:with_merge_requests_enabled]
- options[:with] = Entities::BasicProjectDetails if options[:simple]
+ options[:with] = Entities::BasicProjectDetails if params[:simple]
present paginate(projects), options
end
@@ -95,8 +94,7 @@ module API
use :statistics_params
end
get do
- entity = current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails
- present_projects ProjectsFinder.new(current_user: current_user).execute, with: entity, statistics: params[:statistics]
+ present_projects
end
desc 'Create new project' do