##// END OF EJS Templates
goto-switcher: optimized performance and query capabilities....
marcink -
r2038:2bdf9d4d default
parent child Browse files
Show More
@@ -30,10 +30,11 b' from rhodecode.lib.auth import LoginRequ'
30 from rhodecode.lib.index import searcher_from_config
30 from rhodecode.lib.index import searcher_from_config
31 from rhodecode.lib.utils2 import safe_unicode, str2bool
31 from rhodecode.lib.utils2 import safe_unicode, str2bool
32 from rhodecode.lib.ext_json import json
32 from rhodecode.lib.ext_json import json
33 from rhodecode.model.db import func, Repository, RepoGroup
33 from rhodecode.model.db import (
34 func, or_, in_filter_generator, Repository, RepoGroup)
34 from rhodecode.model.repo import RepoModel
35 from rhodecode.model.repo import RepoModel
35 from rhodecode.model.repo_group import RepoGroupModel
36 from rhodecode.model.repo_group import RepoGroupModel
36 from rhodecode.model.scm import ScmModel, RepoGroupList, RepoList
37 from rhodecode.model.scm import RepoGroupList, RepoList
37 from rhodecode.model.user import UserModel
38 from rhodecode.model.user import UserModel
38 from rhodecode.model.user_group import UserGroupModel
39 from rhodecode.model.user_group import UserGroupModel
39
40
@@ -101,9 +102,17 b' class HomeView(BaseAppView):'
101 return {'suggestions': _user_groups}
102 return {'suggestions': _user_groups}
102
103
103 def _get_repo_list(self, name_contains=None, repo_type=None, limit=20):
104 def _get_repo_list(self, name_contains=None, repo_type=None, limit=20):
105 allowed_ids = self._rhodecode_user.repo_acl_ids(
106 ['repository.read', 'repository.write', 'repository.admin'],
107 cache=False, name_filter=name_contains)
108
104 query = Repository.query()\
109 query = Repository.query()\
105 .order_by(func.length(Repository.repo_name))\
110 .order_by(func.length(Repository.repo_name))\
106 .order_by(Repository.repo_name)
111 .order_by(Repository.repo_name)\
112 .filter(or_(
113 # generate multiple IN to fix limitation problems
114 *in_filter_generator(Repository.repo_id, allowed_ids)
115 ))
107
116
108 if repo_type:
117 if repo_type:
109 query = query.filter(Repository.repo_type == repo_type)
118 query = query.filter(Repository.repo_type == repo_type)
@@ -114,23 +123,30 b' class HomeView(BaseAppView):'
114 Repository.repo_name.ilike(ilike_expression))
123 Repository.repo_name.ilike(ilike_expression))
115 query = query.limit(limit)
124 query = query.limit(limit)
116
125
117 all_repos = query.all()
126 acl_repo_iter = query
118 # permission checks are inside this function
127
119 repo_iter = ScmModel().get_repos(all_repos)
120 return [
128 return [
121 {
129 {
122 'id': obj['name'],
130 'id': obj.repo_name,
123 'text': obj['name'],
131 'text': obj.repo_name,
124 'type': 'repo',
132 'type': 'repo',
125 'obj': obj['dbrepo'],
133 'obj': {'repo_type': obj.repo_type, 'private': obj.private},
126 'url': h.route_path('repo_summary', repo_name=obj['name'])
134 'url': h.route_path('repo_summary', repo_name=obj.repo_name)
127 }
135 }
128 for obj in repo_iter]
136 for obj in acl_repo_iter]
129
137
130 def _get_repo_group_list(self, name_contains=None, limit=20):
138 def _get_repo_group_list(self, name_contains=None, limit=20):
139 allowed_ids = self._rhodecode_user.repo_group_acl_ids(
140 ['group.read', 'group.write', 'group.admin'],
141 cache=False, name_filter=name_contains)
142
131 query = RepoGroup.query()\
143 query = RepoGroup.query()\
132 .order_by(func.length(RepoGroup.group_name))\
144 .order_by(func.length(RepoGroup.group_name))\
133 .order_by(RepoGroup.group_name)
145 .order_by(RepoGroup.group_name) \
146 .filter(or_(
147 # generate multiple IN to fix limitation problems
148 *in_filter_generator(RepoGroup.group_id, allowed_ids)
149 ))
134
150
135 if name_contains:
151 if name_contains:
136 ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
152 ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
@@ -138,8 +154,8 b' class HomeView(BaseAppView):'
138 RepoGroup.group_name.ilike(ilike_expression))
154 RepoGroup.group_name.ilike(ilike_expression))
139 query = query.limit(limit)
155 query = query.limit(limit)
140
156
141 all_groups = query.all()
157 acl_repo_iter = query
142 repo_groups_iter = ScmModel().get_repo_groups(all_groups)
158
143 return [
159 return [
144 {
160 {
145 'id': obj.group_name,
161 'id': obj.group_name,
@@ -149,7 +165,7 b' class HomeView(BaseAppView):'
149 'url': h.route_path(
165 'url': h.route_path(
150 'repo_group_home', repo_group_name=obj.group_name)
166 'repo_group_home', repo_group_name=obj.group_name)
151 }
167 }
152 for obj in repo_groups_iter]
168 for obj in acl_repo_iter]
153
169
154 def _get_hash_commit_list(self, auth_user, query=None):
170 def _get_hash_commit_list(self, auth_user, query=None):
155 if not query or len(query) < 3:
171 if not query or len(query) < 3:
@@ -100,6 +100,24 b' def _hash_key(k):'
100 return md5_safe(k)
100 return md5_safe(k)
101
101
102
102
103 def in_filter_generator(qry, items, limit=500):
104 """
105 Splits IN() into multiple with OR
106 e.g.::
107 cnt = Repository.query().filter(
108 or_(
109 *in_filter_generator(Repository.repo_id, range(100000))
110 )).count()
111 """
112 parts = []
113 for chunk in xrange(0, len(items), limit):
114 parts.append(
115 qry.in_(items[chunk: chunk + limit])
116 )
117
118 return parts
119
120
103 class EncryptedTextValue(TypeDecorator):
121 class EncryptedTextValue(TypeDecorator):
104 """
122 """
105 Special column for encrypted long text data, use like::
123 Special column for encrypted long text data, use like::
General Comments 0
You need to be logged in to leave comments. Login now