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
Hide 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
...
@@ -3,17 +3,13 @@ module Gitlab
class
Activity
class
Activity
attr_reader
:username
attr_reader
:username
def
self
.
from_array
(
activities
)
activities
.
map
{
|
activity
|
new
(
*
activity
)
}
end
def
initialize
(
username
,
time
)
def
initialize
(
username
,
time
)
@username
=
username
@username
=
username
@time
=
time
@time
=
time
end
end
def
date
def
lat_activity_at
@
date
||=
Time
.
at
(
@time
).
utc
.
to_datetime
@
lat_activity_at
||=
Time
.
at
(
@time
).
to_s
(
:db
)
end
end
end
end
end
end
...
...
lib/gitlab/user/activity_set.rb
View file @
9aa64965
module
Gitlab
module
Gitlab
module
User
module
User
class
ActivitySet
class
ActivitySet
include
Gitlab
::
PaginationUtil
KEY
=
'user/activities'
KEY
=
'user/activities'
DEFAULT_PAGE_SIZE
=
50
DEFAULT_FROM
=
6
.
months
.
ago
.
to_i
DEFAULT_FROM
=
1
.
year
.
ago
attr_reader
:page
,
:per_page
def
self
.
record
(
user
)
def
self
.
record
(
user
)
Gitlab
::
Redis
.
with
do
|
redis
|
Gitlab
::
Redis
.
with
do
|
redis
|
...
@@ -11,26 +14,45 @@ module Gitlab
...
@@ -11,26 +14,45 @@ module Gitlab
end
end
end
end
def
self
.
query
(
*
args
)
def
initialize
(
from
:,
page
:,
per_page
:)
new
(
*
args
).
query
@from
=
sanitize_date
(
from
)
@to
=
Time
.
now
.
to_i
@page
=
page
@per_page
=
per_page
end
end
def
initialize
(
from
:,
page
:,
per_page
:)
def
activities
@from
=
from
||
DEFAULT_FROM
@activities
||=
raw_activities
.
map
{
|
activity
|
Activity
.
new
(
*
activity
)
}
@page
=
page
||
0
end
@per_page
=
per_page
||
DEFAULT_PAGE_SIZE
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
end
def
query
def
raw_activities
Gitlab
::
Redis
.
with
do
|
redis
|
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
zrangebyscore
(
KEY
,
@from
.
to_i
,
Time
.
now
.
to_i
,
with_scores:
true
,
limit:
[
offset
,
@per_page
])
redis
.
zrangebyscore
(
KEY
,
@from
,
@to
,
with_scores:
true
,
limit:
[
pagination_delegate
.
offset
,
pagination_delegate
.
limit_value
])
end
end
end
end
private
def
count
Gitlab
::
Redis
.
with
do
|
redis
|
def
offset
redis
.
zcount
(
KEY
,
@from
,
@to
)
@page
*
@per_page
end
end
end
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
...
@@ -39,7 +39,7 @@ describe Gitlab::User::ActivitySet, :redis, lib: true do
end
end
end
end
context
'filter by date'
do
context
'filter by date'
do
before
do
before
do
Timecop
.
freeze
(
Date
.
yesterday
)
Timecop
.
freeze
(
Date
.
yesterday
)
end
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