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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
533cd8c2
Commit
533cd8c2
authored
Apr 21, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throttle the update of `project.last_activity_at` to 1 minute
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
81cb636e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
23 deletions
+45
-23
CHANGELOG
CHANGELOG
+1
-0
app/models/event.rb
app/models/event.rb
+1
-1
spec/models/event_spec.rb
spec/models/event_spec.rb
+43
-22
No files found.
CHANGELOG
View file @
533cd8c2
...
@@ -4,6 +4,7 @@ v 8.8.0 (unreleased)
...
@@ -4,6 +4,7 @@ v 8.8.0 (unreleased)
- Remove future dates from contribution calendar graph.
- Remove future dates from contribution calendar graph.
v 8.7.1 (unreleased)
v 8.7.1 (unreleased)
- Throttle the update of `project.last_activity_at` to 1 minute. !3848
- Fix .gitlab-ci.yml parsing issue when hidde job is a template without script definition. !3849
- Fix .gitlab-ci.yml parsing issue when hidde job is a template without script definition. !3849
- Fix license detection to detect all license files, not only known licenses. !3878
- Fix license detection to detect all license files, not only known licenses. !3878
- Use the `can?` helper instead of `current_user.can?`. !3882
- Use the `can?` helper instead of `current_user.can?`. !3882
...
...
app/models/event.rb
View file @
533cd8c2
...
@@ -345,7 +345,7 @@ class Event < ActiveRecord::Base
...
@@ -345,7 +345,7 @@ class Event < ActiveRecord::Base
end
end
def
reset_project_activity
def
reset_project_activity
if
project
if
project
&&
Gitlab
::
ExclusiveLease
.
new
(
"project:update_last_activity_at:
#{
project
.
id
}
"
,
timeout:
60
).
try_obtain
project
.
update_column
(
:last_activity_at
,
self
.
created_at
)
project
.
update_column
(
:last_activity_at
,
self
.
created_at
)
end
end
end
end
...
...
spec/models/event_spec.rb
View file @
533cd8c2
...
@@ -30,32 +30,29 @@ describe Event, models: true do
...
@@ -30,32 +30,29 @@ describe Event, models: true do
it
{
is_expected
.
to
respond_to
(
:commits
)
}
it
{
is_expected
.
to
respond_to
(
:commits
)
}
end
end
describe
'Callbacks'
do
describe
'after_create :reset_project_activity'
do
let
(
:project
)
{
create
(
:project
)
}
context
"project's last activity was less than 5 minutes ago"
do
it
'does not update project.last_activity_at if it has been touched less than 5 minutes ago'
do
create_event
(
project
,
project
.
owner
)
project
.
update_column
(
:last_activity_at
,
5
.
minutes
.
ago
)
project_last_activity_at
=
project
.
last_activity_at
create_event
(
project
,
project
.
owner
)
expect
(
project
.
last_activity_at
).
to
eq
(
project_last_activity_at
)
end
end
end
end
describe
"Push event"
do
describe
"Push event"
do
before
do
before
do
project
=
create
(
:project
)
project
=
create
(
:project
)
@user
=
project
.
owner
@user
=
project
.
owner
@event
=
create_event
(
project
,
@user
)
data
=
{
before:
Gitlab
::
Git
::
BLANK_SHA
,
after:
"0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e"
,
ref:
"refs/heads/master"
,
user_id:
@user
.
id
,
user_name:
@user
.
name
,
repository:
{
name:
project
.
name
,
url:
"localhost/rubinius"
,
description:
""
,
homepage:
"localhost/rubinius"
,
private:
true
}
}
@event
=
Event
.
create
(
project:
project
,
action:
Event
::
PUSHED
,
data:
data
,
author_id:
@user
.
id
)
end
end
it
{
expect
(
@event
.
push?
).
to
be_truthy
}
it
{
expect
(
@event
.
push?
).
to
be_truthy
}
...
@@ -143,4 +140,28 @@ describe Event, models: true do
...
@@ -143,4 +140,28 @@ describe Event, models: true do
it
{
is_expected
.
to
eq
([
event2
])
}
it
{
is_expected
.
to
eq
([
event2
])
}
end
end
end
end
def
create_event
(
project
,
user
,
attrs
=
{})
data
=
{
before:
Gitlab
::
Git
::
BLANK_SHA
,
after:
"0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e"
,
ref:
"refs/heads/master"
,
user_id:
user
.
id
,
user_name:
user
.
name
,
repository:
{
name:
project
.
name
,
url:
"localhost/rubinius"
,
description:
""
,
homepage:
"localhost/rubinius"
,
private:
true
}
}
Event
.
create
({
project:
project
,
action:
Event
::
PUSHED
,
data:
data
,
author_id:
user
.
id
}.
merge
(
attrs
))
end
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