diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-07-13 18:06:11 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-07-13 18:06:11 +0000 |
commit | b8f67b4ddf6b4a56fc25565d66230fc6e78ba72d (patch) | |
tree | 882af00a70d099a617c8f9acefb048351b32c9ee | |
parent | d2c9e8ab6e696f9b2dd3abcddd7cb526e8057a14 (diff) | |
parent | 228073986bfb900ef324379639e1c5cce6b74fe6 (diff) | |
download | gitlab-ce-b8f67b4ddf6b4a56fc25565d66230fc6e78ba72d.tar.gz |
Merge branch 'dropdown-load-fix' into 'master'
Dropdown loading time preformance fix
## What does this MR do?
Optimizes the performance of the dropdown load time by just sending the required data to load the dropdown instead of the full object
This MR aims to fix #17474
See merge request !5113
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/assets/javascripts/api.js.coffee | 2 | ||||
-rw-r--r-- | lib/api/entities.rb | 1 | ||||
-rw-r--r-- | lib/api/projects.rb | 6 | ||||
-rw-r--r-- | spec/javascripts/project_title_spec.js.coffee | 2 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 12 |
6 files changed, 21 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG index 23f2cd1d1c8..9a31ebfa11d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.10.0 (unreleased) - Expose {should,force}_remove_source_branch (Ben Boeckel) + - Fix projects dropdown loading performance with a simplified api cal. !5113 (tiagonbotelho) - Fix commit builds API, return all builds for all pipelines for given commit. !4849 - Replace Haml with Hamlit to make view rendering faster. !3666 - Expire the branch cache after `git gc` runs diff --git a/app/assets/javascripts/api.js.coffee b/app/assets/javascripts/api.js.coffee index cf46f15a156..89b0ac697ed 100644 --- a/app/assets/javascripts/api.js.coffee +++ b/app/assets/javascripts/api.js.coffee @@ -3,7 +3,7 @@ groupPath: "/api/:version/groups/:id.json" namespacesPath: "/api/:version/namespaces.json" groupProjectsPath: "/api/:version/groups/:id/projects.json" - projectsPath: "/api/:version/projects.json" + projectsPath: "/api/:version/projects.json?simple=true" labelsPath: "/api/:version/projects/:id/labels" licensePath: "/api/:version/licenses/:key" gitignorePath: "/api/:version/gitignores/:key" diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 301dbb688a7..8e03c08f47b 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -54,6 +54,7 @@ module API class BasicProjectDetails < Grape::Entity expose :id + expose :http_url_to_repo, :web_url expose :name, :name_with_namespace expose :path, :path_with_namespace end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 0cc1edd65c8..6d2a6f3946c 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -25,7 +25,11 @@ module API @projects = current_user.authorized_projects @projects = filter_projects(@projects) @projects = paginate @projects - present @projects, with: Entities::ProjectWithAccess, user: current_user + if params[:simple] + present @projects, with: Entities::BasicProjectDetails, user: current_user + else + present @projects, with: Entities::ProjectWithAccess, user: current_user + end end # Get an owned projects list for authenticated user diff --git a/spec/javascripts/project_title_spec.js.coffee b/spec/javascripts/project_title_spec.js.coffee index f0d26fb5446..0244119fa0e 100644 --- a/spec/javascripts/project_title_spec.js.coffee +++ b/spec/javascripts/project_title_spec.js.coffee @@ -22,7 +22,7 @@ describe 'Project Title', -> @projects_data = fixture.load('projects.json')[0] spyOn(jQuery, 'ajax').and.callFake (req) => - expect(req.url).toBe('/api/v3/projects.json') + expect(req.url).toBe('/api/v3/projects.json?simple=true') d = $.Deferred() d.resolve @projects_data d.promise() diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 8a52725a893..152cd802839 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -81,6 +81,18 @@ describe API::API, api: true do expect(json_response.first.keys).not_to include('open_issues_count') end + context 'GET /projects?simple=true' do + it 'returns a simplified version of all the projects' do + expected_keys = ["id", "http_url_to_repo", "web_url", "name", "name_with_namespace", "path", "path_with_namespace"] + + get api('/projects?simple=true', user) + + expect(response).to have_http_status(200) + expect(json_response).to be_an Array + expect(json_response.first.keys).to match_array expected_keys + end + end + context 'and using search' do it 'should return searched project' do get api('/projects', user), { search: project.name } |