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
9aa64965
Commit
9aa64965
authored
Dec 14, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor activity and activity set, and fixed spec
parent
e913cf3f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
21 deletions
+39
-21
lib/gitlab/user/activity.rb
lib/gitlab/user/activity.rb
+2
-6
lib/gitlab/user/activity_set.rb
lib/gitlab/user/activity_set.rb
+36
-14
spec/lib/gitlab/user/activity_set_spec.rb
spec/lib/gitlab/user/activity_set_spec.rb
+1
-1
No files found.
lib/gitlab/user/activity.rb
View file @
9aa64965
...
...
@@ -3,17 +3,13 @@ module Gitlab
class
Activity
attr_reader
:username
def
self
.
from_array
(
activities
)
activities
.
map
{
|
activity
|
new
(
*
activity
)
}
end
def
initialize
(
username
,
time
)
@username
=
username
@time
=
time
end
def
date
@
date
||=
Time
.
at
(
@time
).
utc
.
to_datetime
def
lat_activity_at
@
lat_activity_at
||=
Time
.
at
(
@time
).
to_s
(
:db
)
end
end
end
...
...
lib/gitlab/user/activity_set.rb
View file @
9aa64965
module
Gitlab
module
User
class
ActivitySet
include
Gitlab
::
PaginationUtil
KEY
=
'user/activities'
DEFAULT_PAGE_SIZE
=
50
DEFAULT_FROM
=
1
.
year
.
ago
DEFAULT_FROM
=
6
.
months
.
ago
.
to_i
attr_reader
:page
,
:per_page
def
self
.
record
(
user
)
Gitlab
::
Redis
.
with
do
|
redis
|
...
...
@@ -11,26 +14,45 @@ module Gitlab
end
end
def
self
.
query
(
*
args
)
new
(
*
args
).
query
def
initialize
(
from
:,
page
:,
per_page
:)
@from
=
sanitize_date
(
from
)
@to
=
Time
.
now
.
to_i
@page
=
page
@per_page
=
per_page
end
def
initialize
(
from
:,
page
:,
per_page
:)
@from
=
from
||
DEFAULT_FROM
@page
=
page
||
0
@per_page
=
per_page
||
DEFAULT_PAGE_SIZE
def
activities
@activities
||=
raw_activities
.
map
{
|
activity
|
Activity
.
new
(
*
activity
)
}
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
])
private
def
sanitize_date
(
date
)
Time
.
strptime
(
date
,
"%Y-%m-%d"
).
to_i
rescue
TypeError
,
ArgumentError
DEFAULT_FROM
end
def
pagination_delegate
@pagination_delegate
||=
Gitlab
::
PaginationDelegate
.
new
(
page:
@page
,
per_page:
@per_page
,
count:
count
)
end
private
def
raw_activities
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
zrangebyscore
(
KEY
,
@from
,
@to
,
with_scores:
true
,
limit:
[
pagination_delegate
.
offset
,
pagination_delegate
.
limit_value
])
end
end
def
offset
@page
*
@per_page
def
count
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
zcount
(
KEY
,
@from
,
@to
)
end
end
end
end
...
...
spec/lib/gitlab/user/activity_set_spec.rb
View file @
9aa64965
...
...
@@ -39,7 +39,7 @@ describe Gitlab::User::ActivitySet, :redis, lib: true do
end
end
context
'filter by date'
do
context
'filter by date'
do
before
do
Timecop
.
freeze
(
Date
.
yesterday
)
end
...
...
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