Skip to content
Snippets Groups Projects

Get rid of user activites table and replace it with redis

Merged James Lopez requested to merge fix/user-activities-performance into master
All threads resolved!
@@ -2,6 +2,7 @@
describe Users::ActivityService, services: true do
let(:user) { create(:user) }
let(:key) { 'gitlab:user:activities' }
subject(:service) { described_class.new(user, 'type') }
@@ -15,12 +16,18 @@
expect(last_hour_members).to eq([user.username])
end
it 'updates the last activity timestamp for the user' do
it 'updates the same user' do
service.execute
expect(last_hour_members).to eq([user.username])
end
it 'updates the timestamp of an existing user' do
Timecop.freeze(Date.today + 30) do
expect { service.execute }.to change { user_score }.to(Time.now.to_i)
end
end
describe 'other user' do
it 'updates other user' do
other_user = create(:user)
@@ -43,7 +50,13 @@
def last_hour_members
Gitlab::Redis.with do |redis|
redis.zrangebyscore('gitlab:user:activities', 1.hour.ago.to_i, Time.now.to_i)
redis.zrangebyscore(key, 1.hour.ago.to_i, Time.now.to_i)
end
end
def user_score
Gitlab::Redis.with do |redis|
redis.zscore(key, user.username).to_i
end
end
end
Loading