2018-11-05 23:45:35 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-18 06:05:29 -05:00
|
|
|
module Gitlab
|
|
|
|
module CycleAnalytics
|
|
|
|
class Updater
|
|
|
|
def self.update!(*args)
|
|
|
|
new(*args).update!
|
|
|
|
end
|
|
|
|
|
2016-11-18 07:00:38 -05:00
|
|
|
def initialize(event_result, from:, to:, klass:)
|
2016-11-18 06:05:29 -05:00
|
|
|
@event_result = event_result
|
2016-11-18 07:00:38 -05:00
|
|
|
@klass = klass
|
|
|
|
@from = from
|
|
|
|
@to = to
|
2016-11-18 06:05:29 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def update!
|
|
|
|
@event_result.each do |event|
|
2016-11-18 07:00:38 -05:00
|
|
|
event[@to] = items[event.delete(@from).to_i].first
|
2016-11-18 06:05:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def result_ids
|
2016-11-18 07:00:38 -05:00
|
|
|
@event_result.map { |event| event[@from] }
|
2016-11-18 06:05:29 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def items
|
2016-11-18 07:00:38 -05:00
|
|
|
@items ||= @klass.find(result_ids).group_by { |item| item['id'] }
|
2016-11-18 06:05:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|