2019-02-13 22:33:31 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module Gitlab
|
|
|
|
module CycleAnalytics
|
|
|
|
class Updater
|
|
|
|
def self.update!(*args)
|
|
|
|
new(*args).update!
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(event_result, from:, to:, klass:)
|
|
|
|
@event_result = event_result
|
|
|
|
@klass = klass
|
|
|
|
@from = from
|
|
|
|
@to = to
|
|
|
|
end
|
|
|
|
|
|
|
|
def update!
|
|
|
|
@event_result.each do |event|
|
|
|
|
event[@to] = items[event.delete(@from).to_i].first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def result_ids
|
|
|
|
@event_result.map { |event| event[@from] }
|
|
|
|
end
|
|
|
|
|
|
|
|
def items
|
|
|
|
@items ||= @klass.find(result_ids).group_by { |item| item['id'] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|