Commit b900ab6b authored by Igor Drozdov's avatar Igor Drozdov

Use Gitaly to fetch overview branches

The problem is that we're fetching all branches and then take 5
the most active and then iterate over the whole array until we get
5 branches with committer-date older than 3 months ago.
If we display the stalest branches on the overview, we'll be able
to fetch 5 the most recent and then fetch 5 the oldest.

We perform 2 requests, but they are smaller and don't depend
on the number of branches.
parent cb196194
......@@ -175,19 +175,32 @@ class Projects::BranchesController < Projects::ApplicationController
end
def fetch_branches_by_mode
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
return fetch_branches_for_overview if @mode == 'overview'
# active/stale/all view mode
@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 = Kaminari.paginate_array(@branches).page(params[:page])
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
def confidential_issue_project
......
---
title: Improve UI and performance of branches overview page
merge_request: 50096
author:
type: performance
......@@ -639,6 +639,34 @@ RSpec.describe Projects::BranchesController do
expect(response).to redirect_to project_branches_filtered_path(project, state: 'all')
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
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