diff options
author | James Lopez <james@jameslopez.es> | 2017-01-12 14:48:01 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2017-01-17 13:32:55 +0300 |
commit | 150a448596dda076f0893facbd621429738aba92 (patch) | |
tree | a365c22f24552946c3209355f271bf23872897b7 /lib/gitlab/cycle_analytics | |
parent | 34875ce6b760980c1539c3ab88af0429e04d90bc (diff) |
refactored a bunch of stuff based on feedback
Diffstat (limited to 'lib/gitlab/cycle_analytics')
-rw-r--r-- | lib/gitlab/cycle_analytics/base_event_fetcher.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/base_stage.rb | 20 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/code_stage.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/event_fetcher.rb (renamed from lib/gitlab/cycle_analytics/event.rb) | 2 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/issue_stage.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/plan_stage.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/production_stage.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/review_stage.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/staging_stage.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/test_stage.rb | 9 |
10 files changed, 49 insertions, 43 deletions
diff --git a/lib/gitlab/cycle_analytics/base_event_fetcher.rb b/lib/gitlab/cycle_analytics/base_event_fetcher.rb index 8d10ddf15d7..0d8791d396b 100644 --- a/lib/gitlab/cycle_analytics/base_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/base_event_fetcher.rb @@ -42,7 +42,7 @@ module Gitlab end def default_order - @options[:start_time_attrs].is_a?(Array) ? @options[:start_time_attrs].first : @options[:start_time_attrs] + [@options[:start_time_attrs]].flatten.first end def serialize(_event) diff --git a/lib/gitlab/cycle_analytics/base_stage.rb b/lib/gitlab/cycle_analytics/base_stage.rb index 9143792e044..7ff15051558 100644 --- a/lib/gitlab/cycle_analytics/base_stage.rb +++ b/lib/gitlab/cycle_analytics/base_stage.rb @@ -8,17 +8,11 @@ module Gitlab @options = options end - def event - @event ||= Gitlab::CycleAnalytics::Event[name].new(project: @project, - stage: name, - options: event_options) - end - def events - event.fetch + event_fetcher.fetch end - def median_data + def as_json AnalyticsStageSerializer.new.represent(self).as_json end @@ -35,7 +29,7 @@ module Gitlab # cycle analytics stage. interval_query = Arel::Nodes::As.new( cte_table, - subtract_datetimes(base_query.dup, @start_time_attrs, @end_time_attrs, name.to_s)) + subtract_datetimes(base_query.dup, start_time_attrs, end_time_attrs, name.to_s)) median_datetime(cte_table, interval_query, name) end @@ -46,8 +40,14 @@ module Gitlab private + def event_fetcher + @event_fetcher ||= Gitlab::CycleAnalytics::EventFetcher[name].new(project: @project, + stage: name, + options: event_options) + end + def event_options - @options.merge(start_time_attrs: @start_time_attrs, end_time_attrs: @end_time_attrs) + @options.merge(start_time_attrs: start_time_attrs, end_time_attrs: end_time_attrs) end end end diff --git a/lib/gitlab/cycle_analytics/code_stage.rb b/lib/gitlab/cycle_analytics/code_stage.rb index 111c0e99633..d1bc2055ba8 100644 --- a/lib/gitlab/cycle_analytics/code_stage.rb +++ b/lib/gitlab/cycle_analytics/code_stage.rb @@ -1,11 +1,12 @@ module Gitlab module CycleAnalytics class CodeStage < BaseStage - def initialize(*args) - @start_time_attrs = issue_metrics_table[:first_mentioned_in_commit_at] - @end_time_attrs = mr_table[:created_at] + def start_time_attrs + @start_time_attrs ||= issue_metrics_table[:first_mentioned_in_commit_at] + end - super(*args) + def end_time_attrs + @end_time_attrs ||= mr_table[:created_at] end def name diff --git a/lib/gitlab/cycle_analytics/event.rb b/lib/gitlab/cycle_analytics/event_fetcher.rb index 1ba7bc08ee5..50e126cf00b 100644 --- a/lib/gitlab/cycle_analytics/event.rb +++ b/lib/gitlab/cycle_analytics/event_fetcher.rb @@ -1,6 +1,6 @@ module Gitlab module CycleAnalytics - module Event + module EventFetcher def self.[](stage_name) CycleAnalytics.const_get("#{stage_name.to_s.camelize}EventFetcher") end diff --git a/lib/gitlab/cycle_analytics/issue_stage.rb b/lib/gitlab/cycle_analytics/issue_stage.rb index d320458d7fd..d2068fbc38f 100644 --- a/lib/gitlab/cycle_analytics/issue_stage.rb +++ b/lib/gitlab/cycle_analytics/issue_stage.rb @@ -1,12 +1,13 @@ module Gitlab module CycleAnalytics class IssueStage < BaseStage - def initialize(*args) - @start_time_attrs = issue_table[:created_at] - @end_time_attrs = [issue_metrics_table[:first_associated_with_milestone_at], - issue_metrics_table[:first_added_to_board_at]] + def start_time_attrs + @start_time_attrs ||= issue_table[:created_at] + end - super(*args) + def end_time_attrs + @end_time_attrs ||= [issue_metrics_table[:first_associated_with_milestone_at], + issue_metrics_table[:first_added_to_board_at]] end def name diff --git a/lib/gitlab/cycle_analytics/plan_stage.rb b/lib/gitlab/cycle_analytics/plan_stage.rb index a7164e5c5b7..3b4dfc6a30e 100644 --- a/lib/gitlab/cycle_analytics/plan_stage.rb +++ b/lib/gitlab/cycle_analytics/plan_stage.rb @@ -1,12 +1,13 @@ module Gitlab module CycleAnalytics class PlanStage < BaseStage - def initialize(*args) - @start_time_attrs = [issue_metrics_table[:first_associated_with_milestone_at], - issue_metrics_table[:first_added_to_board_at]] - @end_time_attrs = issue_metrics_table[:first_mentioned_in_commit_at] + def start_time_attrs + @start_time_attrs ||= [issue_metrics_table[:first_associated_with_milestone_at], + issue_metrics_table[:first_added_to_board_at]] + end - super(*args) + def end_time_attrs + @end_time_attrs ||= issue_metrics_table[:first_mentioned_in_commit_at] end def name diff --git a/lib/gitlab/cycle_analytics/production_stage.rb b/lib/gitlab/cycle_analytics/production_stage.rb index eb221c68324..2a6bcc80116 100644 --- a/lib/gitlab/cycle_analytics/production_stage.rb +++ b/lib/gitlab/cycle_analytics/production_stage.rb @@ -3,11 +3,12 @@ module Gitlab class ProductionStage < BaseStage include ProductionHelper - def initialize(*args) - @start_time_attrs = issue_table[:created_at] - @end_time_attrs = mr_metrics_table[:first_deployed_to_production_at] + def start_time_attrs + @start_time_attrs ||= issue_table[:created_at] + end - super(*args) + def end_time_attrs + @end_time_attrs ||= mr_metrics_table[:first_deployed_to_production_at] end def name diff --git a/lib/gitlab/cycle_analytics/review_stage.rb b/lib/gitlab/cycle_analytics/review_stage.rb index 72ce1ed1e16..fbaa3010d81 100644 --- a/lib/gitlab/cycle_analytics/review_stage.rb +++ b/lib/gitlab/cycle_analytics/review_stage.rb @@ -1,11 +1,12 @@ module Gitlab module CycleAnalytics class ReviewStage < BaseStage - def initialize(*args) - @start_time_attrs = mr_table[:created_at] - @end_time_attrs = mr_metrics_table[:merged_at] + def start_time_attrs + @start_time_attrs ||= mr_table[:created_at] + end - super(*args) + def end_time_attrs + @end_time_attrs ||= mr_metrics_table[:merged_at] end def name diff --git a/lib/gitlab/cycle_analytics/staging_stage.rb b/lib/gitlab/cycle_analytics/staging_stage.rb index 398c1b5989a..945909a4d62 100644 --- a/lib/gitlab/cycle_analytics/staging_stage.rb +++ b/lib/gitlab/cycle_analytics/staging_stage.rb @@ -2,12 +2,12 @@ module Gitlab module CycleAnalytics class StagingStage < BaseStage include ProductionHelper + def start_time_attrs + @start_time_attrs ||= mr_metrics_table[:merged_at] + end - def initialize(*args) - @start_time_attrs = mr_metrics_table[:merged_at] - @end_time_attrs = mr_metrics_table[:first_deployed_to_production_at] - - super(*args) + def end_time_attrs + @end_time_attrs ||= mr_metrics_table[:first_deployed_to_production_at] end def name diff --git a/lib/gitlab/cycle_analytics/test_stage.rb b/lib/gitlab/cycle_analytics/test_stage.rb index 7e59745ffef..0079d56e0e4 100644 --- a/lib/gitlab/cycle_analytics/test_stage.rb +++ b/lib/gitlab/cycle_analytics/test_stage.rb @@ -1,11 +1,12 @@ module Gitlab module CycleAnalytics class TestStage < BaseStage - def initialize(*args) - @start_time_attrs = mr_metrics_table[:latest_build_started_at] - @end_time_attrs = mr_metrics_table[:latest_build_finished_at] + def start_time_attrs + @start_time_attrs ||= mr_metrics_table[:latest_build_started_at] + end - super(*args) + def end_time_attrs + @end_time_attrs ||= mr_metrics_table[:latest_build_finished_at] end def name |