Commit 0e4e86b0 authored by Patrick Bajao's avatar Patrick Bajao

Merge branch 'id-optimize-branches-overview' into 'master'

Improve UI and performance of branches overview page

See merge request gitlab-org/gitlab!50096
parents 291770e0 b900ab6b
...@@ -18,8 +18,8 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -18,8 +18,8 @@ class Projects::BranchesController < Projects::ApplicationController
def index def index
respond_to do |format| respond_to do |format|
format.html do format.html do
@sort = params[:sort].presence || sort_value_recently_updated
@mode = params[:state].presence || 'overview' @mode = params[:state].presence || 'overview'
@sort = sort_value_for_mode
@overview_max_branches = 5 @overview_max_branches = 5
# Fetch branches for the specified mode # Fetch branches for the specified mode
...@@ -125,6 +125,12 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -125,6 +125,12 @@ class Projects::BranchesController < Projects::ApplicationController
private private
def sort_value_for_mode
return params[:sort] if params[:sort].present?
'stale' == @mode ? sort_value_oldest_updated : sort_value_recently_updated
end
# It can be expensive to calculate the diverging counts for each # It can be expensive to calculate the diverging counts for each
# branch. Normally the frontend should be specifying a set of branch # branch. Normally the frontend should be specifying a set of branch
# names, but prior to # names, but prior to
...@@ -169,19 +175,32 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -169,19 +175,32 @@ class Projects::BranchesController < Projects::ApplicationController
end end
def fetch_branches_by_mode def fetch_branches_by_mode
if @mode == 'overview' return fetch_branches_for_overview if @mode == 'overview'
# overview mode
@active_branches, @stale_branches = BranchesFinder.new(@repository, sort: sort_value_recently_updated).execute.partition(&:active?)
# Here we get one more branch to indicate if there are more data we're not showing
@active_branches = @active_branches.first(@overview_max_branches + 1)
@stale_branches = @stale_branches.first(@overview_max_branches + 1)
@branches = @active_branches + @stale_branches
else
# active/stale/all view mode # active/stale/all view mode
@branches = BranchesFinder.new(@repository, params.merge(sort: @sort)).execute @branches = BranchesFinder.new(@repository, params.merge(sort: @sort)).execute
@branches = @branches.select { |b| b.state.to_s == @mode } if %w[active stale].include?(@mode) @branches = @branches.select { |b| b.state.to_s == @mode } if %w[active stale].include?(@mode)
@branches = Kaminari.paginate_array(@branches).page(params[:page]) @branches = Kaminari.paginate_array(@branches).page(params[:page])
end end
def fetch_branches_for_overview
# Here we get one more branch to indicate if there are more data we're not showing
limit = @overview_max_branches + 1
if Feature.enabled?(:branch_list_keyset_pagination, project, default_enabled: true)
@active_branches =
BranchesFinder.new(@repository, { per_page: limit, sort: sort_value_recently_updated })
.execute(gitaly_pagination: true).select(&:active?)
@stale_branches =
BranchesFinder.new(@repository, { per_page: limit, sort: sort_value_oldest_updated })
.execute(gitaly_pagination: true).select(&:stale?)
else
@active_branches, @stale_branches = BranchesFinder.new(@repository, sort: sort_value_recently_updated).execute.partition(&:active?)
@active_branches = @active_branches.first(limit)
@stale_branches = @stale_branches.first(limit)
end
@branches = @active_branches + @stale_branches
end end
def confidential_issue_project def confidential_issue_project
......
---
title: Improve UI and performance of branches overview page
merge_request: 50096
author:
type: performance
...@@ -512,7 +512,8 @@ RSpec.describe Projects::BranchesController do ...@@ -512,7 +512,8 @@ RSpec.describe Projects::BranchesController do
state: 'all' state: 'all'
} }
expect(controller.instance_variable_get(:@branch_pipeline_statuses)["master"].group).to eq("success") expect(assigns[:branch_pipeline_statuses]["master"].group).to eq("success")
expect(assigns[:sort]).to eq('updated_desc')
end end
end end
...@@ -543,8 +544,8 @@ RSpec.describe Projects::BranchesController do ...@@ -543,8 +544,8 @@ RSpec.describe Projects::BranchesController do
state: 'all' state: 'all'
} }
expect(controller.instance_variable_get(:@branch_pipeline_statuses)["master"].group).to eq("running") expect(assigns[:branch_pipeline_statuses]["master"].group).to eq("running")
expect(controller.instance_variable_get(:@branch_pipeline_statuses)["test"].group).to eq("success") expect(assigns[:branch_pipeline_statuses]["test"].group).to eq("success")
end end
end end
...@@ -555,10 +556,11 @@ RSpec.describe Projects::BranchesController do ...@@ -555,10 +556,11 @@ RSpec.describe Projects::BranchesController do
params: { params: {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
state: 'all' state: 'stale'
} }
expect(controller.instance_variable_get(:@branch_pipeline_statuses)).to be_blank expect(assigns[:branch_pipeline_statuses]).to be_blank
expect(assigns[:sort]).to eq('updated_asc')
end end
end end
...@@ -573,10 +575,12 @@ RSpec.describe Projects::BranchesController do ...@@ -573,10 +575,12 @@ RSpec.describe Projects::BranchesController do
params: { params: {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
sort: 'name_asc',
state: 'all' state: 'all'
} }
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(assigns[:sort]).to eq('name_asc')
end end
end end
...@@ -635,6 +639,34 @@ RSpec.describe Projects::BranchesController do ...@@ -635,6 +639,34 @@ RSpec.describe Projects::BranchesController do
expect(response).to redirect_to project_branches_filtered_path(project, state: 'all') expect(response).to redirect_to project_branches_filtered_path(project, state: 'all')
end end
end end
context 'fetching branches for overview' do
before do
get :index, format: :html, params: {
namespace_id: project.namespace, project_id: project, state: 'overview'
}
end
it 'sets active and stale branches' do
expect(assigns[:active_branches]).to eq([])
expect(assigns[:stale_branches].map(&:name)).to eq(
["feature", "improve/awesome", "merge-test", "markdown", "feature_conflict", "'test'"]
)
end
context 'branch_list_keyset_pagination is disabled' do
before do
stub_feature_flags(branch_list_keyset_pagination: false)
end
it 'sets active and stale branches' do
expect(assigns[:active_branches]).to eq([])
expect(assigns[:stale_branches].map(&:name)).to eq(
["feature", "improve/awesome", "merge-test", "markdown", "feature_conflict", "'test'"]
)
end
end
end
end end
describe 'GET diverging_commit_counts' do describe 'GET diverging_commit_counts' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment