2018-06-27 03:23:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-07 13:35:32 -05:00
|
|
|
class UpdateUserActivityWorker
|
2017-11-28 11:08:30 -05:00
|
|
|
include ApplicationWorker
|
2017-03-07 13:35:32 -05:00
|
|
|
|
|
|
|
def perform(pairs)
|
|
|
|
pairs = cast_data(pairs)
|
|
|
|
ids = pairs.keys
|
|
|
|
conditions = 'WHEN id = ? THEN ? ' * ids.length
|
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
User.where(id: ids)
|
|
|
|
.update_all([
|
2017-03-07 13:35:32 -05:00
|
|
|
"last_activity_on = CASE #{conditions} ELSE last_activity_on END",
|
|
|
|
*pairs.to_a.flatten
|
|
|
|
])
|
|
|
|
|
|
|
|
Gitlab::UserActivities.new.delete(*ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def cast_data(pairs)
|
|
|
|
pairs.each_with_object({}) do |(key, value), new_pairs|
|
|
|
|
new_pairs[key.to_i] = Time.at(value.to_i).to_s(:db)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|