Mercurial > kallithea
comparison pylons_app/model/hg_model.py @ 482:7afbc45aab28 celery
added caching queries to hg-app
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 17 Sep 2010 21:35:46 +0200 |
parents | fdebc5f67dc6 |
children | 853b9425742a |
comparison
equal
deleted
inserted
replaced
481:4187d93c7c04 | 482:7afbc45aab28 |
---|---|
41 except ImportError: | 41 except ImportError: |
42 sys.stderr.write('You have to import vcs module') | 42 sys.stderr.write('You have to import vcs module') |
43 raise Exception('Unable to import vcs') | 43 raise Exception('Unable to import vcs') |
44 | 44 |
45 def _get_repos_cached_initial(app_globals, initial): | 45 def _get_repos_cached_initial(app_globals, initial): |
46 """ | 46 """return cached dict with repos |
47 return cached dict with repos | |
48 """ | 47 """ |
49 g = app_globals | 48 g = app_globals |
50 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui, initial) | 49 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui, initial) |
51 | 50 |
52 @cache_region('long_term', 'cached_repo_list') | 51 @cache_region('long_term', 'cached_repo_list') |
53 def _get_repos_cached(): | 52 def _get_repos_cached(): |
54 """ | 53 """return cached dict with repos |
55 return cached dict with repos | |
56 """ | 54 """ |
57 log.info('getting all repositories list') | 55 log.info('getting all repositories list') |
58 from pylons import app_globals as g | 56 from pylons import app_globals as g |
59 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) | 57 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) |
60 | 58 |
61 @cache_region('super_short_term', 'cached_repos_switcher_list') | 59 @cache_region('super_short_term', 'cached_repos_switcher_list') |
62 def _get_repos_switcher_cached(cached_repo_list): | 60 def _get_repos_switcher_cached(cached_repo_list): |
63 repos_lst = [] | 61 repos_lst = [] |
64 for repo in sorted(x for x in cached_repo_list.values()): | 62 for repo in sorted(x for x in cached_repo_list.values()): |
65 if HasRepoPermissionAny('repository.write', 'repository.read', 'repository.admin')(repo.name.lower(), 'main page check'): | 63 if HasRepoPermissionAny('repository.write', 'repository.read', |
64 'repository.admin')(repo.name.lower(), 'main page check'): | |
66 repos_lst.append((repo.name.lower(), repo.dbrepo.private,)) | 65 repos_lst.append((repo.name.lower(), repo.dbrepo.private,)) |
67 | 66 |
68 return repos_lst | 67 return repos_lst |
69 | 68 |
70 @cache_region('long_term', 'full_changelog') | 69 @cache_region('long_term', 'full_changelog') |
71 def _full_changelog_cached(repo_name): | 70 def _full_changelog_cached(repo_name): |
72 log.info('getting full changelog for %s', repo_name) | 71 log.info('getting full changelog for %s', repo_name) |
73 return list(reversed(list(HgModel().get_repo(repo_name)))) | 72 return list(reversed(list(HgModel().get_repo(repo_name)))) |
74 | 73 |
75 class HgModel(object): | 74 class HgModel(object): |
76 """ | 75 """Mercurial Model |
77 Mercurial Model | |
78 """ | 76 """ |
79 | 77 |
80 def __init__(self): | 78 def __init__(self): |
81 """ | 79 pass |
82 Constructor | |
83 """ | |
84 | 80 |
85 @staticmethod | 81 @staticmethod |
86 def repo_scan(repos_prefix, repos_path, baseui, initial=False): | 82 def repo_scan(repos_prefix, repos_path, baseui, initial=False): |
87 """ | 83 """ |
88 Listing of repositories in given path. This path should not be a | 84 Listing of repositories in given path. This path should not be a |
90 :param repos_path: path to directory it could take syntax with | 86 :param repos_path: path to directory it could take syntax with |
91 * or ** for deep recursive displaying repositories | 87 * or ** for deep recursive displaying repositories |
92 """ | 88 """ |
93 sa = meta.Session() | 89 sa = meta.Session() |
94 def check_repo_dir(path): | 90 def check_repo_dir(path): |
95 """ | 91 """Checks the repository |
96 Checks the repository | |
97 :param path: | 92 :param path: |
98 """ | 93 """ |
99 repos_path = path.split('/') | 94 repos_path = path.split('/') |
100 if repos_path[-1] in ['*', '**']: | 95 if repos_path[-1] in ['*', '**']: |
101 repos_path = repos_path[:-1] | 96 repos_path = repos_path[:-1] |