##// END OF EJS Templates
shadow-repos: show count of shadow repos for each repo in caches view.
marcink -
r2811:0d542a40 default
parent child Browse files
Show More
@@ -1,80 +1,80 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2011-2018 RhodeCode GmbH
3 # Copyright (C) 2011-2018 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import os
21 import os
22 import logging
22 import logging
23
23
24 from pyramid.httpexceptions import HTTPFound
24 from pyramid.httpexceptions import HTTPFound
25 from pyramid.view import view_config
25 from pyramid.view import view_config
26
26
27 from rhodecode.apps._base import RepoAppView
27 from rhodecode.apps._base import RepoAppView
28 from rhodecode.lib.auth import (
28 from rhodecode.lib.auth import (
29 LoginRequired, HasRepoPermissionAnyDecorator, CSRFRequired)
29 LoginRequired, HasRepoPermissionAnyDecorator, CSRFRequired)
30 from rhodecode.lib import helpers as h
30 from rhodecode.lib import helpers as h
31 from rhodecode.lib import system_info
31 from rhodecode.lib import system_info
32 from rhodecode.model.meta import Session
32 from rhodecode.model.meta import Session
33 from rhodecode.model.scm import ScmModel
33 from rhodecode.model.scm import ScmModel
34
34
35 log = logging.getLogger(__name__)
35 log = logging.getLogger(__name__)
36
36
37
37
38 class RepoCachesView(RepoAppView):
38 class RepoCachesView(RepoAppView):
39 def load_default_context(self):
39 def load_default_context(self):
40 c = self._get_local_tmpl_context()
40 c = self._get_local_tmpl_context()
41 return c
41 return c
42
42
43 @LoginRequired()
43 @LoginRequired()
44 @HasRepoPermissionAnyDecorator('repository.admin')
44 @HasRepoPermissionAnyDecorator('repository.admin')
45 @view_config(
45 @view_config(
46 route_name='edit_repo_caches', request_method='GET',
46 route_name='edit_repo_caches', request_method='GET',
47 renderer='rhodecode:templates/admin/repos/repo_edit.mako')
47 renderer='rhodecode:templates/admin/repos/repo_edit.mako')
48 def repo_caches(self):
48 def repo_caches(self):
49 c = self.load_default_context()
49 c = self.load_default_context()
50 c.active = 'caches'
50 c.active = 'caches'
51 cached_diffs_dir = c.rhodecode_db_repo.cached_diffs_dir
51 cached_diffs_dir = c.rhodecode_db_repo.cached_diffs_dir
52 c.cached_diff_count = len(c.rhodecode_db_repo.cached_diffs())
52 c.cached_diff_count = len(c.rhodecode_db_repo.cached_diffs())
53 c.cached_diff_size = 0
53 c.cached_diff_size = 0
54 if os.path.isdir(cached_diffs_dir):
54 if os.path.isdir(cached_diffs_dir):
55 c.cached_diff_size = system_info.get_storage_size(cached_diffs_dir)
55 c.cached_diff_size = system_info.get_storage_size(cached_diffs_dir)
56
56 c.shadow_repos = c.rhodecode_db_repo.shadow_repos()
57 return self._get_template_context(c)
57 return self._get_template_context(c)
58
58
59 @LoginRequired()
59 @LoginRequired()
60 @HasRepoPermissionAnyDecorator('repository.admin')
60 @HasRepoPermissionAnyDecorator('repository.admin')
61 @CSRFRequired()
61 @CSRFRequired()
62 @view_config(
62 @view_config(
63 route_name='edit_repo_caches', request_method='POST')
63 route_name='edit_repo_caches', request_method='POST')
64 def repo_caches_purge(self):
64 def repo_caches_purge(self):
65 _ = self.request.translate
65 _ = self.request.translate
66 c = self.load_default_context()
66 c = self.load_default_context()
67 c.active = 'caches'
67 c.active = 'caches'
68
68
69 try:
69 try:
70 ScmModel().mark_for_invalidation(self.db_repo_name, delete=True)
70 ScmModel().mark_for_invalidation(self.db_repo_name, delete=True)
71 Session().commit()
71 Session().commit()
72 h.flash(_('Cache invalidation successful'),
72 h.flash(_('Cache invalidation successful'),
73 category='success')
73 category='success')
74 except Exception:
74 except Exception:
75 log.exception("Exception during cache invalidation")
75 log.exception("Exception during cache invalidation")
76 h.flash(_('An error occurred during cache invalidation'),
76 h.flash(_('An error occurred during cache invalidation'),
77 category='error')
77 category='error')
78
78
79 raise HTTPFound(h.route_path(
79 raise HTTPFound(h.route_path(
80 'edit_repo_caches', repo_name=self.db_repo_name)) No newline at end of file
80 'edit_repo_caches', repo_name=self.db_repo_name))
@@ -1,76 +1,98 b''
1 <div class="panel panel-default">
1 <div class="panel panel-default">
2 <div class="panel-heading">
2 <div class="panel-heading">
3 <h3 class="panel-title">${_('Invalidate Cache for Repository')}</h3>
3 <h3 class="panel-title">${_('Invalidate Cache for Repository')}</h3>
4 </div>
4 </div>
5 <div class="panel-body">
5 <div class="panel-body">
6
6
7 <h4>${_('Manually invalidate the repository cache. On the next access a repository cache will be recreated.')}</h4>
7 <h4>${_('Manually invalidate the repository cache. On the next access a repository cache will be recreated.')}</h4>
8
8
9 <p>
9 <p>
10 ${_('Cache purge can be automated by such api call. Can be called periodically in crontab etc.')}
10 ${_('Cache purge can be automated by such api call. Can be called periodically in crontab etc.')}
11 <br/>
11 <br/>
12 <code>
12 <code>
13 ${h.api_call_example(method='invalidate_cache', args={"repoid": c.rhodecode_db_repo.repo_name})}
13 ${h.api_call_example(method='invalidate_cache', args={"repoid": c.rhodecode_db_repo.repo_name})}
14 </code>
14 </code>
15 </p>
15 </p>
16
16
17 ${h.secure_form(h.route_path('edit_repo_caches', repo_name=c.repo_name), request=request)}
17 ${h.secure_form(h.route_path('edit_repo_caches', repo_name=c.repo_name), request=request)}
18 <div class="form">
18 <div class="form">
19 <div class="fields">
19 <div class="fields">
20 ${h.submit('reset_cache_%s' % c.rhodecode_db_repo.repo_name,_('Invalidate repository cache'),class_="btn btn-small",onclick="return confirm('"+_('Confirm to invalidate repository cache')+"');")}
20 ${h.submit('reset_cache_%s' % c.rhodecode_db_repo.repo_name,_('Invalidate repository cache'),class_="btn btn-small",onclick="return confirm('"+_('Confirm to invalidate repository cache')+"');")}
21 </div>
21 </div>
22 </div>
22 </div>
23 ${h.end_form()}
23 ${h.end_form()}
24
24
25 </div>
25 </div>
26 </div>
26 </div>
27
27
28
28
29 <div class="panel panel-default">
29 <div class="panel panel-default">
30 <div class="panel-heading">
30 <div class="panel-heading">
31 <h3 class="panel-title">
31 <h3 class="panel-title">
32 ${(_ungettext('List of repository caches (%(count)s entry)', 'List of repository caches (%(count)s entries)' ,len(c.rhodecode_db_repo.cache_keys)) % {'count': len(c.rhodecode_db_repo.cache_keys)})}
32 ${(_ungettext('List of repository caches (%(count)s entry)', 'List of repository caches (%(count)s entries)' ,len(c.rhodecode_db_repo.cache_keys)) % {'count': len(c.rhodecode_db_repo.cache_keys)})}
33 </h3>
33 </h3>
34 </div>
34 </div>
35 <div class="panel-body">
35 <div class="panel-body">
36 <div class="field" >
36 <div class="field" >
37 <table class="rctable edit_cache">
37 <table class="rctable edit_cache">
38 <tr>
38 <tr>
39 <th>${_('Prefix')}</th>
39 <th>${_('Prefix')}</th>
40 <th>${_('Key')}</th>
40 <th>${_('Key')}</th>
41 <th>${_('Active')}</th>
41 <th>${_('Active')}</th>
42 </tr>
42 </tr>
43 %for cache in c.rhodecode_db_repo.cache_keys:
43 %for cache in c.rhodecode_db_repo.cache_keys:
44 <tr>
44 <tr>
45 <td class="td-prefix">${cache.get_prefix() or '-'}</td>
45 <td class="td-prefix">${cache.get_prefix() or '-'}</td>
46 <td class="td-cachekey">${cache.cache_key}</td>
46 <td class="td-cachekey">${cache.cache_key}</td>
47 <td class="td-active">${h.bool2icon(cache.cache_active)}</td>
47 <td class="td-active">${h.bool2icon(cache.cache_active)}</td>
48 </tr>
48 </tr>
49 %endfor
49 %endfor
50 </table>
50 </table>
51 </div>
51 </div>
52 </div>
52 </div>
53 </div>
53 </div>
54
54
55 <div class="panel panel-default">
56 <div class="panel-heading">
57 <h3 class="panel-title">${_('Shadow Repositories')}</h3>
58 </div>
59 <div class="panel-body">
60 <table class="rctable edit_cache">
61 % if c.shadow_repos:
62 % for shadow_repo in c.shadow_repos:
63 <tr>
64 <td>${shadow_repo}</td>
65 </tr>
66 % endfor
67 % else:
68 <tr>
69 <td>${_('No Shadow repositories exist for this repository.')}</td>
70 </tr>
71 % endif
72
73 </table>
74 </div>
75 </div>
76
55
77
56 <div class="panel panel-default">
78 <div class="panel panel-default">
57 <div class="panel-heading">
79 <div class="panel-heading">
58 <h3 class="panel-title">${_('Diff Caches')}</h3>
80 <h3 class="panel-title">${_('Diff Caches')}</h3>
59 </div>
81 </div>
60 <div class="panel-body">
82 <div class="panel-body">
61 <table class="rctable edit_cache">
83 <table class="rctable edit_cache">
62 <tr>
84 <tr>
63 <td>${_('Cached diff name')}:</td>
85 <td>${_('Cached diff name')}:</td>
64 <td>${c.rhodecode_db_repo.cached_diffs_relative_dir}</td>
86 <td>${c.rhodecode_db_repo.cached_diffs_relative_dir}</td>
65 </tr>
87 </tr>
66 <tr>
88 <tr>
67 <td>${_('Cached diff files')}:</td>
89 <td>${_('Cached diff files')}:</td>
68 <td>${c.cached_diff_count}</td>
90 <td>${c.cached_diff_count}</td>
69 </tr>
91 </tr>
70 <tr>
92 <tr>
71 <td>${_('Cached diff size')}:</td>
93 <td>${_('Cached diff size')}:</td>
72 <td>${h.format_byte_size(c.cached_diff_size)}</td>
94 <td>${h.format_byte_size(c.cached_diff_size)}</td>
73 </tr>
95 </tr>
74 </table>
96 </table>
75 </div>
97 </div>
76 </div>
98 </div>
General Comments 0
You need to be logged in to leave comments. Login now