##// END OF EJS Templates
summary: use non-memory cache for readme, and cleanup cache for repo stats.
marcink -
r3892:8afbef06 default
parent child Browse files
Show More
@@ -60,9 +60,8 b' class RepoSummaryView(RepoAppView):'
60 if isinstance(landing_commit, EmptyCommit):
60 if isinstance(landing_commit, EmptyCommit):
61 return None, None
61 return None, None
62
62
63 cache_namespace_uid = 'cache_repo_instance.{}_{}'.format(
63 cache_namespace_uid = 'cache_repo.{}'.format(db_repo.repo_id)
64 db_repo.repo_id, CacheKey.CACHE_TYPE_README)
64 region = rc_cache.get_or_create_region('cache_repo', cache_namespace_uid)
65 region = rc_cache.get_or_create_region('cache_repo_longterm', cache_namespace_uid)
66 start = time.time()
65 start = time.time()
67
66
68 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid)
67 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid)
@@ -234,9 +233,6 b' class RepoSummaryView(RepoAppView):'
234
233
235 return self._get_template_context(c)
234 return self._get_template_context(c)
236
235
237 def get_request_commit_id(self):
238 return self.request.matchdict['commit_id']
239
240 @LoginRequired()
236 @LoginRequired()
241 @HasRepoPermissionAnyDecorator(
237 @HasRepoPermissionAnyDecorator(
242 'repository.read', 'repository.write', 'repository.admin')
238 'repository.read', 'repository.write', 'repository.admin')
@@ -244,33 +240,35 b' class RepoSummaryView(RepoAppView):'
244 route_name='repo_stats', request_method='GET',
240 route_name='repo_stats', request_method='GET',
245 renderer='json_ext')
241 renderer='json_ext')
246 def repo_stats(self):
242 def repo_stats(self):
247 commit_id = self.get_request_commit_id()
248 show_stats = bool(self.db_repo.enable_statistics)
243 show_stats = bool(self.db_repo.enable_statistics)
249 repo_id = self.db_repo.repo_id
244 repo_id = self.db_repo.repo_id
250
245
251 cache_seconds = safe_int(
246 landing_commit = self.db_repo.get_landing_commit()
252 rhodecode.CONFIG.get('rc_cache.cache_repo.expiration_time'))
247 if isinstance(landing_commit, EmptyCommit):
248 return {'size': 0, 'code_stats': {}}
249
250 cache_seconds = safe_int(rhodecode.CONFIG.get('rc_cache.cache_repo.expiration_time'))
253 cache_on = cache_seconds > 0
251 cache_on = cache_seconds > 0
252
254 log.debug(
253 log.debug(
255 'Computing REPO TREE for repo_id %s commit_id `%s` '
254 'Computing REPO STATS for repo_id %s commit_id `%s` '
256 'with caching: %s[TTL: %ss]' % (
255 'with caching: %s[TTL: %ss]' % (
257 repo_id, commit_id, cache_on, cache_seconds or 0))
256 repo_id, landing_commit, cache_on, cache_seconds or 0))
258
257
259 cache_namespace_uid = 'cache_repo.{}'.format(repo_id)
258 cache_namespace_uid = 'cache_repo.{}'.format(repo_id)
260 region = rc_cache.get_or_create_region('cache_repo', cache_namespace_uid)
259 region = rc_cache.get_or_create_region('cache_repo', cache_namespace_uid)
261
260
262 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid,
261 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid,
263 condition=cache_on)
262 condition=cache_on)
264 def compute_stats(repo_id, commit_id, show_stats):
263 def compute_stats(repo_id, commit_id, _show_stats):
265 code_stats = {}
264 code_stats = {}
266 size = 0
265 size = 0
267 try:
266 try:
268 scm_instance = self.db_repo.scm_instance()
267 commit = self.db_repo.get_commit(commit_id)
269 commit = scm_instance.get_commit(commit_id)
270
268
271 for node in commit.get_filenodes_generator():
269 for node in commit.get_filenodes_generator():
272 size += node.size
270 size += node.size
273 if not show_stats:
271 if not _show_stats:
274 continue
272 continue
275 ext = string.lower(node.extension)
273 ext = string.lower(node.extension)
276 ext_info = LANGUAGES_EXTENSIONS_MAP.get(ext)
274 ext_info = LANGUAGES_EXTENSIONS_MAP.get(ext)
@@ -284,7 +282,7 b' class RepoSummaryView(RepoAppView):'
284 return {'size': h.format_byte_size_binary(size),
282 return {'size': h.format_byte_size_binary(size),
285 'code_stats': code_stats}
283 'code_stats': code_stats}
286
284
287 stats = compute_stats(self.db_repo.repo_id, commit_id, show_stats)
285 stats = compute_stats(self.db_repo.repo_id, landing_commit.raw_id, show_stats)
288 return stats
286 return stats
289
287
290 @LoginRequired()
288 @LoginRequired()
@@ -3505,7 +3505,7 b' class CacheKey(Base, BaseModel):'
3505 )
3505 )
3506
3506
3507 CACHE_TYPE_FEED = 'FEED'
3507 CACHE_TYPE_FEED = 'FEED'
3508 CACHE_TYPE_README = 'README'
3508
3509 # namespaces used to register process/thread aware caches
3509 # namespaces used to register process/thread aware caches
3510 REPO_INVALIDATION_NAMESPACE = 'repo_cache:{repo_id}'
3510 REPO_INVALIDATION_NAMESPACE = 'repo_cache:{repo_id}'
3511 SETTINGS_INVALIDATION_NAMESPACE = 'system_settings'
3511 SETTINGS_INVALIDATION_NAMESPACE = 'system_settings'
@@ -564,7 +564,7 b' def test_invalidation_context(baseapp):'
564 repo_id = 9999
564 repo_id = 9999
565
565
566 cache_namespace_uid = 'cache_repo_instance.{}_{}'.format(
566 cache_namespace_uid = 'cache_repo_instance.{}_{}'.format(
567 repo_id, CacheKey.CACHE_TYPE_README)
567 repo_id, CacheKey.CACHE_TYPE_FEED)
568 invalidation_namespace = CacheKey.REPO_INVALIDATION_NAMESPACE.format(
568 invalidation_namespace = CacheKey.REPO_INVALIDATION_NAMESPACE.format(
569 repo_id=repo_id)
569 repo_id=repo_id)
570 region = rc_cache.get_or_create_region('cache_repo_longterm', cache_namespace_uid)
570 region = rc_cache.get_or_create_region('cache_repo_longterm', cache_namespace_uid)
@@ -627,7 +627,7 b' def test_invalidation_context_exception_'
627 repo_id = 888
627 repo_id = 888
628
628
629 cache_namespace_uid = 'cache_repo_instance.{}_{}'.format(
629 cache_namespace_uid = 'cache_repo_instance.{}_{}'.format(
630 repo_id, CacheKey.CACHE_TYPE_README)
630 repo_id, CacheKey.CACHE_TYPE_FEED)
631 invalidation_namespace = CacheKey.REPO_INVALIDATION_NAMESPACE.format(
631 invalidation_namespace = CacheKey.REPO_INVALIDATION_NAMESPACE.format(
632 repo_id=repo_id)
632 repo_id=repo_id)
633 region = rc_cache.get_or_create_region('cache_repo_longterm', cache_namespace_uid)
633 region = rc_cache.get_or_create_region('cache_repo_longterm', cache_namespace_uid)
@@ -656,7 +656,7 b' def test_cache_invalidation_race_conditi'
656 repo_id = 777
656 repo_id = 777
657
657
658 cache_namespace_uid = 'cache_repo_instance.{}_{}'.format(
658 cache_namespace_uid = 'cache_repo_instance.{}_{}'.format(
659 repo_id, CacheKey.CACHE_TYPE_README)
659 repo_id, CacheKey.CACHE_TYPE_FEED)
660 invalidation_namespace = CacheKey.REPO_INVALIDATION_NAMESPACE.format(
660 invalidation_namespace = CacheKey.REPO_INVALIDATION_NAMESPACE.format(
661 repo_id=repo_id)
661 repo_id=repo_id)
662 region = rc_cache.get_or_create_region('cache_repo_longterm', cache_namespace_uid)
662 region = rc_cache.get_or_create_region('cache_repo_longterm', cache_namespace_uid)
General Comments 0
You need to be logged in to leave comments. Login now