Commit 2f808329 authored by James Lopez's avatar James Lopez

added user activities redis logic

parent e5686a29
...@@ -948,9 +948,7 @@ class User < ActiveRecord::Base ...@@ -948,9 +948,7 @@ class User < ActiveRecord::Base
end end
def record_activity def record_activity
Gitlab::Redis.with do |redis| Gitlab::UserActivities.record(self)
redis.zadd('user/activities', Time.now.to_i, self.username)
end
end end
private private
......
module Gitlab
class UserActivities
KEY = 'user/activities'
DEFAULT_PAGE_SIZE = 50
def self.record(user)
Gitlab::Redis.with do |redis|
redis.zadd(KEY, Time.now.to_i, user.username)
end
end
def self.query(*args)
new(*args).query
end
def initialize(from: 6.months.ago, page: 0, per_page: DEFAULT_PAGE_SIZE)
@from = from
@page = page
@per_page = per_page
end
def query
Gitlab::Redis.with do |redis|
redis.zrangebyscore(KEY, @from.to_i, Time.now.to_i, with_scores: true, limit: [offset, @per_page])
end
end
private
def offset
@page * @per_page
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment