Welcome to mirror list, hosted at ThFree Co, Russian Federation.

update_user_activity_worker.rb « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 15f01a703375e4330c36e0b6819a78700d1c91b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

class UpdateUserActivityWorker
  include ApplicationWorker

  def perform(pairs)
    pairs = cast_data(pairs)
    ids = pairs.keys
    conditions = 'WHEN id = ? THEN ? ' * ids.length

    User.where(id: ids)
      .update_all([
        "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