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
Boxiang Sun
gitlab-ce
Commits
61ea2f52
Commit
61ea2f52
authored
May 28, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throttle updates to Project#last_repository_updated_at.
Closes #35364.
parent
71dea693
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
0 deletions
+20
-0
app/models/event.rb
app/models/event.rb
+2
-0
changelogs/unreleased/ab-35364-throttle-updates-last-repository-at.yml
...released/ab-35364-throttle-updates-last-repository-at.yml
+5
-0
spec/models/event_spec.rb
spec/models/event_spec.rb
+13
-0
No files found.
app/models/event.rb
View file @
61ea2f52
...
@@ -40,6 +40,7 @@ class Event < ActiveRecord::Base
...
@@ -40,6 +40,7 @@ class Event < ActiveRecord::Base
).
freeze
).
freeze
RESET_PROJECT_ACTIVITY_INTERVAL
=
1
.
hour
RESET_PROJECT_ACTIVITY_INTERVAL
=
1
.
hour
REPOSITORY_UPDATED_AT_INTERVAL
=
5
.
minutes
delegate
:name
,
:email
,
:public_email
,
:username
,
to: :author
,
prefix:
true
,
allow_nil:
true
delegate
:name
,
:email
,
:public_email
,
:username
,
to: :author
,
prefix:
true
,
allow_nil:
true
delegate
:title
,
to: :issue
,
prefix:
true
,
allow_nil:
true
delegate
:title
,
to: :issue
,
prefix:
true
,
allow_nil:
true
...
@@ -391,6 +392,7 @@ class Event < ActiveRecord::Base
...
@@ -391,6 +392,7 @@ class Event < ActiveRecord::Base
def
set_last_repository_updated_at
def
set_last_repository_updated_at
Project
.
unscoped
.
where
(
id:
project_id
)
Project
.
unscoped
.
where
(
id:
project_id
)
.
where
(
"last_repository_updated_at < ? OR last_repository_updated_at IS NULL"
,
REPOSITORY_UPDATED_AT_INTERVAL
.
ago
)
.
update_all
(
last_repository_updated_at:
created_at
)
.
update_all
(
last_repository_updated_at:
created_at
)
end
end
...
...
changelogs/unreleased/ab-35364-throttle-updates-last-repository-at.yml
0 → 100644
View file @
61ea2f52
---
title
:
Throttle updates to Project#last_repository_updated_at.
merge_request
:
19183
author
:
type
:
performance
spec/models/event_spec.rb
View file @
61ea2f52
...
@@ -50,6 +50,19 @@ describe Event do
...
@@ -50,6 +50,19 @@ describe Event do
end
end
end
end
describe
'#set_last_repository_updated_at'
do
it
'only updates once every Event::REPOSITORY_UPDATED_AT_INTERVAL minutes'
do
last_known_timestamp
=
(
Event
::
REPOSITORY_UPDATED_AT_INTERVAL
-
1
.
minute
).
ago
project
.
update
(
last_repository_updated_at:
last_known_timestamp
)
project
.
reload
# a reload removes fractions of seconds
expect
do
create_push_event
(
project
,
project
.
owner
)
project
.
reload
end
.
not_to
change
{
project
.
last_repository_updated_at
}
end
end
describe
'after_create :track_user_interacted_projects'
do
describe
'after_create :track_user_interacted_projects'
do
let
(
:event
)
{
build
(
:push_event
,
project:
project
,
author:
project
.
owner
)
}
let
(
:event
)
{
build
(
:push_event
,
project:
project
,
author:
project
.
owner
)
}
...
...
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