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

user_activities.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 125488536e19408c280bf2f3db29d30ab93cdffb (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
28
29
30
31
32
33
34
module Gitlab
  class UserActivities
    include Enumerable

    KEY = 'users:activities'.freeze
    BATCH_SIZE = 500

    def self.record(key, time = Time.now)
      Gitlab::Redis::SharedState.with do |redis|
        redis.hset(KEY, key, time.to_i)
      end
    end

    def delete(*keys)
      Gitlab::Redis::SharedState.with do |redis|
        redis.hdel(KEY, keys)
      end
    end

    def each
      cursor = 0
      loop do
        cursor, pairs =
          Gitlab::Redis::SharedState.with do |redis|
            redis.hscan(KEY, cursor, count: BATCH_SIZE)
          end

        Hash[pairs].each { |pair| yield pair }

        break if cursor == '0'
      end
    end
  end
end