2017-08-17 22:00:37 +05:30
|
|
|
module Gitlab
|
|
|
|
class UserActivities
|
|
|
|
include Enumerable
|
|
|
|
|
|
|
|
KEY = 'users:activities'.freeze
|
|
|
|
BATCH_SIZE = 500
|
|
|
|
|
|
|
|
def self.record(key, time = Time.now)
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
2017-08-17 22:00:37 +05:30
|
|
|
redis.hset(KEY, key, time.to_i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete(*keys)
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
2017-08-17 22:00:37 +05:30
|
|
|
redis.hdel(KEY, keys)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def each
|
|
|
|
cursor = 0
|
|
|
|
loop do
|
|
|
|
cursor, pairs =
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
2017-08-17 22:00:37 +05:30
|
|
|
redis.hscan(KEY, cursor, count: BATCH_SIZE)
|
|
|
|
end
|
|
|
|
|
|
|
|
Hash[pairs].each { |pair| yield pair }
|
|
|
|
|
|
|
|
break if cursor == '0'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|