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
074a1797
Commit
074a1797
authored
Apr 05, 2019
by
Hiroyuki Sato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the project statistics immediatelly
parent
e6780501
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
0 deletions
+11
-0
app/workers/project_cache_worker.rb
app/workers/project_cache_worker.rb
+7
-0
spec/workers/project_cache_worker_spec.rb
spec/workers/project_cache_worker_spec.rb
+4
-0
No files found.
app/workers/project_cache_worker.rb
View file @
074a1797
...
@@ -26,10 +26,17 @@ class ProjectCacheWorker
...
@@ -26,10 +26,17 @@ class ProjectCacheWorker
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
# NOTE: triggering both an immediate update and one in 15 minutes if we
# successfully obtain the lease. That way, we only need to wait for the
# statistics to become accurate if they were already updated once in the
# last 15 minutes.
def
update_statistics
(
project
,
statistics
=
[])
def
update_statistics
(
project
,
statistics
=
[])
return
if
Gitlab
::
Database
.
read_only?
return
if
Gitlab
::
Database
.
read_only?
return
unless
try_obtain_lease_for
(
project
.
id
,
statistics
)
return
unless
try_obtain_lease_for
(
project
.
id
,
statistics
)
Rails
.
logger
.
info
(
"Updating statistics for project
#{
project
.
id
}
"
)
project
.
statistics
.
refresh!
(
only:
statistics
)
UpdateProjectStatisticsWorker
.
perform_in
(
LEASE_TIMEOUT
,
project
.
id
,
statistics
)
UpdateProjectStatisticsWorker
.
perform_in
(
LEASE_TIMEOUT
,
project
.
id
,
statistics
)
end
end
...
...
spec/workers/project_cache_worker_spec.rb
View file @
074a1797
...
@@ -86,6 +86,10 @@ describe ProjectCacheWorker do
...
@@ -86,6 +86,10 @@ describe ProjectCacheWorker do
it
'updates the project statistics'
do
it
'updates the project statistics'
do
stub_exclusive_lease
(
lease_key
,
timeout:
lease_timeout
)
stub_exclusive_lease
(
lease_key
,
timeout:
lease_timeout
)
expect
(
project
.
statistics
).
to
receive
(
:refresh!
)
.
with
(
only:
statistics
.
map
(
&
:to_sym
))
.
and_call_original
expect
(
UpdateProjectStatisticsWorker
).
to
receive
(
:perform_in
)
expect
(
UpdateProjectStatisticsWorker
).
to
receive
(
:perform_in
)
.
with
(
lease_timeout
,
project
.
id
,
statistics
.
map
(
&
:to_sym
))
.
with
(
lease_timeout
,
project
.
id
,
statistics
.
map
(
&
:to_sym
))
.
and_call_original
.
and_call_original
...
...
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