Commit 198df06f authored by Małgorzata Ksionek's avatar Małgorzata Ksionek

Add attribute reader

parent 2d283dd4
...@@ -5,7 +5,7 @@ module Gitlab ...@@ -5,7 +5,7 @@ module Gitlab
class BaseEventFetcher class BaseEventFetcher
include BaseQuery include BaseQuery
attr_reader :projections, :query, :stage, :order attr_reader :projections, :query, :stage, :order, :project, :options
MAX_EVENTS = 50 MAX_EVENTS = 50
...@@ -40,13 +40,13 @@ module Gitlab ...@@ -40,13 +40,13 @@ module Gitlab
end end
def events_query def events_query
diff_fn = subtract_datetimes_diff(base_query, @options[:start_time_attrs], @options[:end_time_attrs]) diff_fn = subtract_datetimes_diff(base_query, options[:start_time_attrs], options[:end_time_attrs])
base_query.project(extract_diff_epoch(diff_fn).as('total_time'), *projections).order(order.desc).take(MAX_EVENTS) base_query.project(extract_diff_epoch(diff_fn).as('total_time'), *projections).order(order.desc).take(MAX_EVENTS)
end end
def default_order def default_order
[@options[:start_time_attrs]].flatten.first [options[:start_time_attrs]].flatten.first
end end
def serialize(_event) def serialize(_event)
...@@ -59,7 +59,7 @@ module Gitlab ...@@ -59,7 +59,7 @@ module Gitlab
def allowed_ids def allowed_ids
@allowed_ids ||= allowed_ids_finder_class @allowed_ids ||= allowed_ids_finder_class
.new(@options[:current_user], allowed_ids_source) .new(options[:current_user], allowed_ids_source)
.execute.where(id: event_result_ids).pluck(:id) .execute.where(id: event_result_ids).pluck(:id)
end end
...@@ -68,11 +68,11 @@ module Gitlab ...@@ -68,11 +68,11 @@ module Gitlab
end end
def allowed_ids_source def allowed_ids_source
{ project_id: @project.id } { project_id: project.id }
end end
def projects def projects
[@project] [project]
end end
end end
end end
......
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
.join(issue_metrics_table).on(issue_table[:id].eq(issue_metrics_table[:issue_id])) .join(issue_metrics_table).on(issue_table[:id].eq(issue_metrics_table[:issue_id]))
.project(issue_table[:project_id].as("project_id")) .project(issue_table[:project_id].as("project_id"))
.where(issue_table[:project_id].in(project_ids)) .where(issue_table[:project_id].in(project_ids))
.where(issue_table[:created_at].gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables .where(issue_table[:created_at].gteq(options[:from]))
# Load merge_requests # Load merge_requests
query = query.join(mr_table, Arel::Nodes::OuterJoin) query = query.join(mr_table, Arel::Nodes::OuterJoin)
......
...@@ -5,6 +5,8 @@ module Gitlab ...@@ -5,6 +5,8 @@ module Gitlab
class BaseStage class BaseStage
include BaseQuery include BaseQuery
attr_reader :project, :options
def initialize(project: nil, options:) def initialize(project: nil, options:)
@project = project @project = project
@options = options @options = options
...@@ -23,11 +25,11 @@ module Gitlab ...@@ -23,11 +25,11 @@ module Gitlab
end end
def median def median
return if @project.nil? return if project.nil?
BatchLoader.for(@project.id).batch(key: name) do |project_ids, loader| BatchLoader.for(project.id).batch(key: name) do |project_ids, loader|
if project_ids.one? if project_ids.one?
loader.call(@project.id, median_query(project_ids)) loader.call(project.id, median_query(project_ids))
else else
begin begin
median_datetimes(cte_table, interval_query(project_ids), name, :project_id)&.each do |project_id, median| median_datetimes(cte_table, interval_query(project_ids), name, :project_id)&.each do |project_id, median|
...@@ -65,17 +67,17 @@ module Gitlab ...@@ -65,17 +67,17 @@ module Gitlab
private private
def event_fetcher def event_fetcher
@event_fetcher ||= Gitlab::CycleAnalytics::EventFetcher[name].new(project: @project, @event_fetcher ||= Gitlab::CycleAnalytics::EventFetcher[name].new(project: project,
stage: name, stage: name,
options: event_options) options: event_options)
end end
def event_options 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
def projects def projects
[@project] [project]
end end
end end
end end
......
...@@ -20,7 +20,7 @@ module Gitlab ...@@ -20,7 +20,7 @@ module Gitlab
private private
def serialize(event) def serialize(event)
AnalyticsMergeRequestSerializer.new(project: @project).represent(event) AnalyticsMergeRequestSerializer.new(project: project).represent(event)
end end
def allowed_ids_finder_class def allowed_ids_finder_class
......
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
private private
def serialize(event) def serialize(event)
AnalyticsIssueSerializer.new(project: @project).represent(event) AnalyticsIssueSerializer.new(project: project).represent(event)
end end
def allowed_ids_finder_class def allowed_ids_finder_class
......
...@@ -7,7 +7,7 @@ module Gitlab ...@@ -7,7 +7,7 @@ module Gitlab
query = issue_table.join(issue_metrics_table).on(issue_table[:id].eq(issue_metrics_table[:issue_id])) query = issue_table.join(issue_metrics_table).on(issue_table[:id].eq(issue_metrics_table[:issue_id]))
.project(issue_table[:project_id].as("project_id")) .project(issue_table[:project_id].as("project_id"))
.where(issue_table[:project_id].in(project_ids)) .where(issue_table[:project_id].in(project_ids))
.where(issue_table[:created_at].gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables .where(issue_table[:created_at].gteq(options[:from]))
.where(issue_metrics_table[:first_added_to_board_at].not_eq(nil).or(issue_metrics_table[:first_associated_with_milestone_at].not_eq(nil))) .where(issue_metrics_table[:first_added_to_board_at].not_eq(nil).or(issue_metrics_table[:first_associated_with_milestone_at].not_eq(nil)))
query query
......
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
private private
def serialize(event) def serialize(event)
AnalyticsIssueSerializer.new(project: @project).represent(event) AnalyticsIssueSerializer.new(project: project).represent(event)
end end
def allowed_ids_finder_class def allowed_ids_finder_class
......
...@@ -7,7 +7,7 @@ module Gitlab ...@@ -7,7 +7,7 @@ module Gitlab
query = issue_table.join(issue_metrics_table).on(issue_table[:id].eq(issue_metrics_table[:issue_id])) query = issue_table.join(issue_metrics_table).on(issue_table[:id].eq(issue_metrics_table[:issue_id]))
.project(issue_table[:project_id].as("project_id")) .project(issue_table[:project_id].as("project_id"))
.where(issue_table[:project_id].in(project_ids)) .where(issue_table[:project_id].in(project_ids))
.where(issue_table[:created_at].gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables .where(issue_table[:created_at].gteq(options[:from]))
.where(issue_metrics_table[:first_added_to_board_at].not_eq(nil).or(issue_metrics_table[:first_associated_with_milestone_at].not_eq(nil))) .where(issue_metrics_table[:first_added_to_board_at].not_eq(nil).or(issue_metrics_table[:first_associated_with_milestone_at].not_eq(nil)))
.where(issue_metrics_table[:first_mentioned_in_commit_at].not_eq(nil)) .where(issue_metrics_table[:first_mentioned_in_commit_at].not_eq(nil))
......
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
private private
def serialize(event) def serialize(event)
AnalyticsIssueSerializer.new(project: @project).represent(event) AnalyticsIssueSerializer.new(project: project).represent(event)
end end
def allowed_ids_finder_class def allowed_ids_finder_class
......
...@@ -6,7 +6,7 @@ module Gitlab ...@@ -6,7 +6,7 @@ module Gitlab
def stage_query(project_ids) def stage_query(project_ids)
super(project_ids) super(project_ids)
.where(mr_metrics_table[:first_deployed_to_production_at] .where(mr_metrics_table[:first_deployed_to_production_at]
.gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables .gteq(options[:from]))
end end
end end
end end
......
...@@ -19,7 +19,7 @@ module Gitlab ...@@ -19,7 +19,7 @@ module Gitlab
private private
def serialize(event) def serialize(event)
AnalyticsMergeRequestSerializer.new(project: @project).represent(event) AnalyticsMergeRequestSerializer.new(project: project).represent(event)
end end
def allowed_ids_finder_class def allowed_ids_finder_class
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
private private
def branch def branch
@branch ||= @options[:branch] # rubocop:disable Gitlab/ModuleWithInstanceVariables @branch ||= options[:branch]
end 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