Commit 244ec0a8 authored by Timothy Andrew's avatar Timothy Andrew

Implement fourth round of comments from @DouweM.

- Pluralize summary titles
- Remove the `run_query` method - always return sql strings from the
  `date_time_sql` methods
parent cc3adcd4
class Projects::CycleAnalyticsController < Projects::ApplicationController class Projects::CycleAnalyticsController < Projects::ApplicationController
include ActionView::Helpers::DateHelper include ActionView::Helpers::DateHelper
include ActionView::Helpers::TextHelper
before_action :authorize_read_cycle_analytics! before_action :authorize_read_cycle_analytics!
...@@ -48,10 +49,14 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController ...@@ -48,10 +49,14 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
stats stats
end end
issues = @cycle_analytics.summary.new_issues
commits = @cycle_analytics.summary.commits
deploys = @cycle_analytics.summary.deploys
summary = [ summary = [
{ title: "New Issues", value: @cycle_analytics.summary.new_issues }, { title: "New Issue".pluralize(issues), value: issues },
{ title: "Commits", value: @cycle_analytics.summary.commits }, { title: "Commit".pluralize(commits), value: commits },
{ title: "Deploys", value: @cycle_analytics.summary.deploys } { title: "Deploy".pluralize(deploys), value: deploys }
] ]
{ {
......
...@@ -10,7 +10,9 @@ module Gitlab ...@@ -10,7 +10,9 @@ module Gitlab
mysql_median_datetime_sql(arel_table, query_so_far, column_sym) mysql_median_datetime_sql(arel_table, query_so_far, column_sym)
end end
results = Array.wrap(median_queries).map { |query| Util.run_query(query) } results = Array.wrap(median_queries).map do |query|
ActiveRecord::Base.connection.execute(query)
end
extract_median(results).presence extract_median(results).presence
end end
...@@ -46,7 +48,7 @@ module Gitlab ...@@ -46,7 +48,7 @@ module Gitlab
Arel.sql("CREATE TEMPORARY TABLE IF NOT EXISTS #{query_so_far.to_sql}"), Arel.sql("CREATE TEMPORARY TABLE IF NOT EXISTS #{query_so_far.to_sql}"),
Arel.sql("set @ct := (select count(1) from #{arel_table.table_name});"), Arel.sql("set @ct := (select count(1) from #{arel_table.table_name});"),
Arel.sql("set @row_id := 0;"), Arel.sql("set @row_id := 0;"),
query, query.to_sql,
Arel.sql("DROP TEMPORARY TABLE IF EXISTS #{arel_table.table_name};") Arel.sql("DROP TEMPORARY TABLE IF EXISTS #{arel_table.table_name};")
] ]
end end
...@@ -87,7 +89,8 @@ module Gitlab ...@@ -87,7 +89,8 @@ module Gitlab
) )
) )
). ).
with(query_so_far, cte) with(query_so_far, cte).
to_sql
end end
private private
......
module Gitlab
module Database
module Util
class << self
def run_query(query)
query = query.to_sql unless query.is_a?(String)
ActiveRecord::Base.connection.execute(query)
end
end
end
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