Commit 693878cf3898b2161904f28db971acf78bfd1ae5
1 parent
3471e26f
Exists in
master
and in
4 other branches
Cache repo size inside repo model
Showing
1 changed file
with
16 additions
and
0 deletions
Show diff stats
app/models/repository.rb
... | ... | @@ -37,6 +37,22 @@ class Repository |
37 | 37 | raw_repository.send(m, *args, &block) |
38 | 38 | end |
39 | 39 | |
40 | + # Return repo size in megabytes | |
41 | + # Cached in redis | |
42 | + def size | |
43 | + Rails.cache.fetch(cache_key(:size)) do | |
44 | + raw_repository.size | |
45 | + end | |
46 | + end | |
47 | + | |
48 | + def expire_cache | |
49 | + Rails.cache.delete(cache_key(:size)) | |
50 | + end | |
51 | + | |
52 | + def cache_key(type) | |
53 | + "#{type}:#{path_with_namespace}" | |
54 | + end | |
55 | + | |
40 | 56 | def respond_to?(method) |
41 | 57 | return true if raw_repository.respond_to?(method) |
42 | 58 | ... | ... |