Commit 1fc89ca9 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'if-24642-activity_service_optimization' into 'master'

Optimize Redis usage in User::ActivityService

See merge request gitlab-org/gitlab-ce!25005
parents ed7144ad a0e97b1c
......@@ -26,12 +26,15 @@ module Users
def record_activity
return if Gitlab::Database.read_only?
today = Date.today
return if @user.last_activity_on == today
lease = Gitlab::ExclusiveLease.new("acitvity_service:#{@user.id}",
timeout: LEASE_TIMEOUT)
return unless lease.try_obtain
@user.update_attribute(:last_activity_on, Date.today)
Rails.logger.debug("Recorded activity: #{@activity} for User ID: #{@user.id} (username: #{@user.username})")
@user.update_attribute(:last_activity_on, today)
end
end
end
---
title: Optimize Redis usage in User::ActivityService
merge_request: 25005
author:
type: performance
......@@ -26,6 +26,12 @@ describe Users::ActivityService do
.from(last_activity_on)
.to(Date.today)
end
it 'tries to obtain ExclusiveLease' do
expect(Gitlab::ExclusiveLease).to receive(:new).and_call_original
subject.execute
end
end
context 'when a bad object is passed' do
......@@ -46,6 +52,12 @@ describe Users::ActivityService do
it 'does not update last_activity_on' do
expect { subject.execute }.not_to change(user, :last_activity_on)
end
it 'does not try to obtain ExclusiveLease' do
expect(Gitlab::ExclusiveLease).not_to receive(:new)
subject.execute
end
end
context 'when in GitLab read-only instance' do
......
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