Improve performance for pipeline charts

Achieved by using another table, which both has better indexes and
is smaller. Now the data provided for the user is more valueable too.
This commit is contained in:
Z.J. van de Weg 2017-06-22 14:37:59 +02:00
parent 9c7bf12356
commit 13d39971f3
5 changed files with 21 additions and 19 deletions

View file

@ -136,6 +136,11 @@ class Projects::PipelinesController < Projects::ApplicationController
@charts[:month] = Ci::Charts::MonthChart.new(project)
@charts[:year] = Ci::Charts::YearChart.new(project)
@charts[:build_times] = Ci::Charts::BuildTime.new(project)
@counts = {}
@counts[:total] = @project.pipelines.count(:all)
@counts[:success] = @project.pipelines.success.count(:all)
@counts[:failed] = @project.pipelines.failed.count(:all)
end
private

View file

@ -17,13 +17,10 @@ module GraphHelper
ids.zip(parent_spaces)
end
def success_ratio(success_builds, failed_builds)
failed_builds = failed_builds.count(:all)
success_builds = success_builds.count(:all)
def success_ratio(success:, failed:)
return 100 if failed.zero?
return 100 if failed_builds.zero?
ratio = (success_builds.to_f / (success_builds + failed_builds)) * 100
ratio = (success.to_f / (success + failed)) * 100
ratio.to_i
end
end

View file

@ -2,18 +2,14 @@
%ul
%li
Total:
%strong= pluralize @project.builds.count(:all), 'job'
%strong= pluralize @counts[:total], 'job'
%li
Successful:
%strong= pluralize @project.builds.success.count(:all), 'job'
%strong= pluralize @counts[:success], 'job'
%li
Failed:
%strong= pluralize @project.builds.failed.count(:all), 'job'
%strong= pluralize @counts[:failed], 'job'
%li
Success ratio:
%strong
#{success_ratio(@project.builds.success, @project.builds.failed)}%
%li
Commits covered:
%strong
= @project.pipelines.count(:all)
#{success_ratio(@counts)}%

View file

@ -0,0 +1,4 @@
---
title: Improve performance of the pipeline charts page
merge_request: 12378
author:

View file

@ -3,7 +3,7 @@ module Ci
module DailyInterval
def grouped_count(query)
query
.group("DATE(#{Ci::Build.table_name}.created_at)")
.group("DATE(#{Ci::Pipeline.table_name}.created_at)")
.count(:created_at)
.transform_keys { |date| date.strftime(@format) }
end
@ -17,12 +17,12 @@ module Ci
def grouped_count(query)
if Gitlab::Database.postgresql?
query
.group("to_char(#{Ci::Build.table_name}.created_at, '01 Month YYYY')")
.group("to_char(#{Ci::Pipeline.table_name}.created_at, '01 Month YYYY')")
.count(:created_at)
.transform_keys(&:squish)
else
query
.group("DATE_FORMAT(#{Ci::Build.table_name}.created_at, '01 %M %Y')")
.group("DATE_FORMAT(#{Ci::Pipeline.table_name}.created_at, '01 %M %Y')")
.count(:created_at)
end
end
@ -46,8 +46,8 @@ module Ci
end
def collect
query = project.builds
.where("? > #{Ci::Build.table_name}.created_at AND #{Ci::Build.table_name}.created_at > ?", @to, @from)
query = project.pipelines
.where("? > #{Ci::Pipeline.table_name}.created_at AND #{Ci::Pipeline.table_name}.created_at > ?", @to, @from)
totals_count = grouped_count(query)
success_count = grouped_count(query.success)