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