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

Add attribute reader

parent 2d283dd4
......@@ -5,7 +5,7 @@ module Gitlab
class BaseEventFetcher
include BaseQuery
attr_reader :projections, :query, :stage, :order
attr_reader :projections, :query, :stage, :order, :project, :options
MAX_EVENTS = 50
......@@ -40,13 +40,13 @@ module Gitlab
end
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)
end
def default_order
[@options[:start_time_attrs]].flatten.first
[options[:start_time_attrs]].flatten.first
end
def serialize(_event)
......@@ -59,7 +59,7 @@ module Gitlab
def allowed_ids
@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)
end
......@@ -68,11 +68,11 @@ module Gitlab
end
def allowed_ids_source
{ project_id: @project.id }
{ project_id: project.id }
end
def projects
[@project]
[project]
end
end
end
......
......@@ -18,7 +18,7 @@ module Gitlab
.join(issue_metrics_table).on(issue_table[:id].eq(issue_metrics_table[:issue_id]))
.project(issue_table[:project_id].as("project_id"))
.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
query = query.join(mr_table, Arel::Nodes::OuterJoin)
......
......@@ -5,6 +5,8 @@ module Gitlab
class BaseStage
include BaseQuery
attr_reader :project, :options
def initialize(project: nil, options:)
@project = project
@options = options
......@@ -23,11 +25,11 @@ module Gitlab
end
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?
loader.call(@project.id, median_query(project_ids))
loader.call(project.id, median_query(project_ids))
else
begin
median_datetimes(cte_table, interval_query(project_ids), name, :project_id)&.each do |project_id, median|
......@@ -65,17 +67,17 @@ module Gitlab
private
def event_fetcher
@event_fetcher ||= Gitlab::CycleAnalytics::EventFetcher[name].new(project: @project,
@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
def projects
[@project]
[project]
end
end
end
......
......@@ -20,7 +20,7 @@ module Gitlab
private
def serialize(event)
AnalyticsMergeRequestSerializer.new(project: @project).represent(event)
AnalyticsMergeRequestSerializer.new(project: project).represent(event)
end
def allowed_ids_finder_class
......
......@@ -18,7 +18,7 @@ module Gitlab
private
def serialize(event)
AnalyticsIssueSerializer.new(project: @project).represent(event)
AnalyticsIssueSerializer.new(project: project).represent(event)
end
def allowed_ids_finder_class
......
......@@ -7,7 +7,7 @@ module Gitlab
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"))
.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)))
query
......
......@@ -18,7 +18,7 @@ module Gitlab
private
def serialize(event)
AnalyticsIssueSerializer.new(project: @project).represent(event)
AnalyticsIssueSerializer.new(project: project).represent(event)
end
def allowed_ids_finder_class
......
......@@ -7,7 +7,7 @@ module Gitlab
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"))
.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_mentioned_in_commit_at].not_eq(nil))
......
......@@ -18,7 +18,7 @@ module Gitlab
private
def serialize(event)
AnalyticsIssueSerializer.new(project: @project).represent(event)
AnalyticsIssueSerializer.new(project: project).represent(event)
end
def allowed_ids_finder_class
......
......@@ -6,7 +6,7 @@ module Gitlab
def stage_query(project_ids)
super(project_ids)
.where(mr_metrics_table[:first_deployed_to_production_at]
.gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables
.gteq(options[:from]))
end
end
end
......
......@@ -19,7 +19,7 @@ module Gitlab
private
def serialize(event)
AnalyticsMergeRequestSerializer.new(project: @project).represent(event)
AnalyticsMergeRequestSerializer.new(project: project).represent(event)
end
def allowed_ids_finder_class
......
......@@ -14,7 +14,7 @@ module Gitlab
private
def branch
@branch ||= @options[:branch] # rubocop:disable Gitlab/ModuleWithInstanceVariables
@branch ||= options[:branch]
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