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
21b48715
Commit
21b48715
authored
Jul 21, 2020
by
Ragnar Hardarson
Committed by
Michael Kozono
Jul 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cache to storage_size DB hits
parent
c639cb5b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
3 deletions
+36
-3
ee/app/models/ee/namespace/root_storage_size.rb
ee/app/models/ee/namespace/root_storage_size.rb
+11
-3
ee/spec/models/namespace/root_storage_size_spec.rb
ee/spec/models/namespace/root_storage_size_spec.rb
+25
-0
No files found.
ee/app/models/ee/namespace/root_storage_size.rb
View file @
21b48715
...
...
@@ -2,6 +2,10 @@
module
EE
class
Namespace::RootStorageSize
CURRENT_SIZE_CACHE_KEY
=
'root_storage_current_size'
LIMIT_CACHE_KEY
=
'root_storage_size_limit'
EXPIRATION_TIME
=
10
.
minutes
def
initialize
(
root_namespace
)
@root_namespace
=
root_namespace
end
...
...
@@ -17,13 +21,17 @@ module EE
end
def
current_size
@current_size
||=
root_namespace
.
root_storage_statistics
&
.
storage_size
@current_size
||=
Rails
.
cache
.
fetch
([
'namespaces'
,
root_namespace
.
id
,
CURRENT_SIZE_CACHE_KEY
],
expires_in:
EXPIRATION_TIME
)
do
root_namespace
.
root_storage_statistics
&
.
storage_size
end
end
def
limit
@limit
||=
root_namespace
.
actual_limits
.
storage_size_limit
.
megabytes
+
@limit
||=
Rails
.
cache
.
fetch
([
'namespaces'
,
root_namespace
.
id
,
LIMIT_CACHE_KEY
],
expires_in:
EXPIRATION_TIME
)
do
root_namespace
.
actual_limits
.
storage_size_limit
.
megabytes
+
root_namespace
.
additional_purchased_storage_size
.
megabytes
end
end
private
...
...
ee/spec/models/namespace/root_storage_size_spec.rb
View file @
21b48715
...
...
@@ -62,6 +62,16 @@ RSpec.describe Namespace::RootStorageSize, type: :model do
subject
{
model
.
current_size
}
it
{
is_expected
.
to
eq
(
current_size
)
}
context
'caches values'
,
:use_clean_rails_memory_store_caching
do
let
(
:key
)
{
'root_storage_current_size'
}
it
'caches the value'
do
subject
expect
(
Rails
.
cache
.
read
([
'namespaces'
,
namespace
.
id
,
key
])).
to
eq
(
current_size
)
end
end
end
describe
'#limit'
do
...
...
@@ -93,5 +103,20 @@ RSpec.describe Namespace::RootStorageSize, type: :model do
it
{
is_expected
.
to
eq
(
0
)
}
end
context
'caches values'
,
:use_clean_rails_memory_store_caching
do
let
(
:key
)
{
'root_storage_size_limit'
}
before
do
plan_limits
.
update!
(
storage_size_limit:
70_000
)
namespace
.
update!
(
additional_purchased_storage_size:
34_000
)
end
it
'caches the value'
do
subject
expect
(
Rails
.
cache
.
read
([
'namespaces'
,
namespace
.
id
,
key
])).
to
eq
(
104_000
.
megabytes
)
end
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