Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9d95687e
Commit
9d95687e
authored
Feb 14, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
632110b5
1fc89ca9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
2 deletions
+22
-2
app/services/users/activity_service.rb
app/services/users/activity_service.rb
+5
-2
changelogs/unreleased/24642-activity_service_optimization.yml
...gelogs/unreleased/24642-activity_service_optimization.yml
+5
-0
spec/services/users/activity_service_spec.rb
spec/services/users/activity_service_spec.rb
+12
-0
No files found.
app/services/users/activity_service.rb
View file @
9d95687e
...
...
@@ -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
changelogs/unreleased/24642-activity_service_optimization.yml
0 → 100644
View file @
9d95687e
---
title
:
Optimize Redis usage in User::ActivityService
merge_request
:
25005
author
:
type
:
performance
spec/services/users/activity_service_spec.rb
View file @
9d95687e
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment