debian-mirror-gitlab/app/workers/update_user_activity_worker.rb

26 lines
562 B
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
class UpdateUserActivityWorker
2018-03-17 18:26:18 +05:30
include ApplicationWorker
2017-08-17 22:00:37 +05:30
def perform(pairs)
pairs = cast_data(pairs)
ids = pairs.keys
conditions = 'WHEN id = ? THEN ? ' * ids.length
2017-09-10 17:25:29 +05:30
User.where(id: ids)
.update_all([
2017-08-17 22:00:37 +05:30
"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