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
5e01ee78
Commit
5e01ee78
authored
Jul 18, 2018
by
Peter Marko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update total storage size when changing size of artifacts
parent
20938681
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
3 deletions
+31
-3
app/models/project_statistics.rb
app/models/project_statistics.rb
+20
-3
changelogs/unreleased/fix-storage-size-for-artifacts-change.yml
...logs/unreleased/fix-storage-size-for-artifacts-change.yml
+5
-0
spec/models/project_statistics_spec.rb
spec/models/project_statistics_spec.rb
+6
-0
No files found.
app/models/project_statistics.rb
View file @
5e01ee78
...
...
@@ -5,7 +5,7 @@ class ProjectStatistics < ActiveRecord::Base
before_save
:update_storage_size
COLUMNS_TO_REFRESH
=
[
:repository_size
,
:lfs_objects_size
,
:commit_count
].
freeze
INCREMENTABLE_COLUMNS
=
[
:build_artifacts_size
]
.
freeze
INCREMENTABLE_COLUMNS
=
{
build_artifacts_size:
%i[storage_size]
}
.
freeze
def
total_repository_size
repository_size
+
lfs_objects_size
...
...
@@ -38,11 +38,28 @@ class ProjectStatistics < ActiveRecord::Base
self
.
storage_size
=
repository_size
+
lfs_objects_size
+
build_artifacts_size
end
# Since this incremental update method does not call update_storage_size above,
# we have to update the storage_size here as additional column.
# Additional columns are updated depending on key => [columns], which allows
# to update statistics which are and also those which aren't included in storage_size
# or any other additional summary column in the future.
def
self
.
increment_statistic
(
project_id
,
key
,
amount
)
raise
ArgumentError
,
"Cannot increment attribute:
#{
key
}
"
unless
key
.
in?
(
INCREMENTABLE_COLUMNS
)
raise
ArgumentError
,
"Cannot increment attribute:
#{
key
}
"
unless
INCREMENTABLE_COLUMNS
.
key?
(
key
)
return
if
amount
==
0
where
(
project_id:
project_id
)
.
update_all
([
"
#{
key
}
= COALESCE(
#{
key
}
, 0) + (?)"
,
amount
])
.
columns_to_increment
(
key
,
amount
)
end
def
self
.
columns_to_increment
(
key
,
amount
)
updates
=
[
"
#{
key
}
= COALESCE(
#{
key
}
, 0) + (
#{
amount
}
)"
]
if
(
additional
=
INCREMENTABLE_COLUMNS
[
key
])
additional
.
each
do
|
column
|
updates
<<
"
#{
column
}
= COALESCE(
#{
column
}
, 0) + (
#{
amount
}
)"
end
end
update_all
(
updates
.
join
(
', '
))
end
end
changelogs/unreleased/fix-storage-size-for-artifacts-change.yml
0 → 100644
View file @
5e01ee78
---
title
:
Update total storage size when changing size of artifacts
merge_request
:
20697
author
:
Peter Marko
type
:
fixed
spec/models/project_statistics_spec.rb
View file @
5e01ee78
...
...
@@ -128,6 +128,12 @@ describe ProjectStatistics do
.
by
(
13
)
end
it
'increases also storage size by that amount'
do
expect
{
described_class
.
increment_statistic
(
project
.
id
,
:build_artifacts_size
,
20
)
}
.
to
change
{
statistics
.
reload
.
storage_size
}
.
by
(
20
)
end
context
'when the amount is 0'
do
it
'does not execute a query'
do
project
...
...
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