Commit 13d39971 authored by Z.J. van de Weg's avatar Z.J. van de Weg

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.
parent 9c7bf123
......@@ -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
......
......@@ -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
......@@ -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)}%
---
title: Improve performance of the pipeline charts page
merge_request: 12378
author:
......@@ -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)
......
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