diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-04-29 00:04:56 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-04-29 00:04:56 +0400 |
commit | 693878cf3898b2161904f28db971acf78bfd1ae5 (patch) | |
tree | c858fb707ea318a2d8f00de6b45cc5bb76132292 /app | |
parent | 3471e26fb218ce3f827c652792ac6c429c861fc0 (diff) |
Cache repo size inside repo model
Diffstat (limited to 'app')
-rw-r--r-- | app/models/repository.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index ed600e29232..d45ec9bd575 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -37,6 +37,22 @@ class Repository raw_repository.send(m, *args, &block) end + # Return repo size in megabytes + # Cached in redis + def size + Rails.cache.fetch(cache_key(:size)) do + raw_repository.size + end + end + + def expire_cache + Rails.cache.delete(cache_key(:size)) + end + + def cache_key(type) + "#{type}:#{path_with_namespace}" + end + def respond_to?(method) return true if raw_repository.respond_to?(method) |