Commit e37383d4 authored by Stan Hu's avatar Stan Hu

Cache FindCommit results in pipelines view

For each pipeline, the controller will call `Pipeline#latest?` to
determine if the pipeline's ref is the latest for that branch.
Since it's likely that the same branches are being used in each
pipeline, we can reduce Gitaly overhead by caching the results
of the FindCommit call.
parent ee89d955
...@@ -31,10 +31,7 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -31,10 +31,7 @@ class Projects::PipelinesController < Projects::ApplicationController
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL) Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL)
render json: { render json: {
pipelines: PipelineSerializer pipelines: serialize_pipelines,
.new(project: @project, current_user: @current_user)
.with_pagination(request, response)
.represent(@pipelines, disable_coverage: true, preload: true),
count: { count: {
all: @pipelines_count, all: @pipelines_count,
running: @running_count, running: @running_count,
...@@ -150,6 +147,15 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -150,6 +147,15 @@ class Projects::PipelinesController < Projects::ApplicationController
private private
def serialize_pipelines
::Gitlab::GitalyClient.allow_ref_name_caching do
PipelineSerializer
.new(project: @project, current_user: @current_user)
.with_pagination(request, response)
.represent(@pipelines, disable_coverage: true, preload: true)
end
end
def render_show def render_show
respond_to do |format| respond_to do |format|
format.html do format.html do
......
---
title: Cache FindCommit results in pipelines view
merge_request: 26776
author:
type: performance
...@@ -28,6 +28,8 @@ describe Projects::PipelinesController do ...@@ -28,6 +28,8 @@ describe Projects::PipelinesController do
end end
it 'returns serialized pipelines', :request_store do it 'returns serialized pipelines', :request_store do
expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original
queries = ActiveRecord::QueryRecorder.new do queries = ActiveRecord::QueryRecorder.new do
get_pipelines_index_json get_pipelines_index_json
end end
......
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