##// END OF EJS Templates
Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
marcink -
r2604:dfa5180c beta
parent child Browse files
Show More
@@ -51,7 +51,8 b' class HomeController(BaseController):'
51 if request.is_xhr:
51 if request.is_xhr:
52 all_repos = Repository.query().order_by(Repository.repo_name).all()
52 all_repos = Repository.query().order_by(Repository.repo_name).all()
53 c.repos_list = self.scm_model.get_repos(all_repos,
53 c.repos_list = self.scm_model.get_repos(all_repos,
54 sort_key='name_sort')
54 sort_key='name_sort',
55 simple=True)
55 return render('/repo_switcher_list.html')
56 return render('/repo_switcher_list.html')
56 else:
57 else:
57 return HTTPBadRequest()
58 return HTTPBadRequest()
@@ -66,6 +66,10 b' class RepoTemp(object):'
66
66
67
67
68 class CachedRepoList(object):
68 class CachedRepoList(object):
69 """
70 Cached repo list, uses in-memory cache after initialization, that is
71 super fast
72 """
69
73
70 def __init__(self, db_repo_list, repos_path, order_by=None):
74 def __init__(self, db_repo_list, repos_path, order_by=None):
71 self.db_repo_list = db_repo_list
75 self.db_repo_list = db_repo_list
@@ -106,7 +110,7 b' class CachedRepoList(object):'
106 tmp_d['name'] = dbr.repo_name
110 tmp_d['name'] = dbr.repo_name
107 tmp_d['name_sort'] = tmp_d['name'].lower()
111 tmp_d['name_sort'] = tmp_d['name'].lower()
108 tmp_d['description'] = dbr.description
112 tmp_d['description'] = dbr.description
109 tmp_d['description_sort'] = tmp_d['description']
113 tmp_d['description_sort'] = tmp_d['description'].lower()
110 tmp_d['last_change'] = last_change
114 tmp_d['last_change'] = last_change
111 tmp_d['last_change_sort'] = time.mktime(last_change.timetuple())
115 tmp_d['last_change_sort'] = time.mktime(last_change.timetuple())
112 tmp_d['tip'] = tip.raw_id
116 tmp_d['tip'] = tip.raw_id
@@ -123,6 +127,29 b' class CachedRepoList(object):'
123 yield tmp_d
127 yield tmp_d
124
128
125
129
130 class SimpleCachedRepoList(CachedRepoList):
131 """
132 Lighter version of CachedRepoList without the scm initialisation
133 """
134
135 def __iter__(self):
136 for dbr in self.db_repo_list:
137 # check permission at this level
138 if not HasRepoPermissionAny(
139 'repository.read', 'repository.write', 'repository.admin'
140 )(dbr.repo_name, 'get repo check'):
141 continue
142
143 tmp_d = {}
144 tmp_d['name'] = dbr.repo_name
145 tmp_d['name_sort'] = tmp_d['name'].lower()
146 tmp_d['description'] = dbr.description
147 tmp_d['description_sort'] = tmp_d['description'].lower()
148 tmp_d['dbrepo'] = dbr.get_dict()
149 tmp_d['dbrepo_fork'] = dbr.fork.get_dict() if dbr.fork else {}
150 yield tmp_d
151
152
126 class GroupList(object):
153 class GroupList(object):
127
154
128 def __init__(self, db_repo_group_list):
155 def __init__(self, db_repo_group_list):
@@ -215,21 +242,29 b' class ScmModel(BaseModel):'
215
242
216 return repos
243 return repos
217
244
218 def get_repos(self, all_repos=None, sort_key=None):
245 def get_repos(self, all_repos=None, sort_key=None, simple=False):
219 """
246 """
220 Get all repos from db and for each repo create it's
247 Get all repos from db and for each repo create it's
221 backend instance and fill that backed with information from database
248 backend instance and fill that backed with information from database
222
249
223 :param all_repos: list of repository names as strings
250 :param all_repos: list of repository names as strings
224 give specific repositories list, good for filtering
251 give specific repositories list, good for filtering
252
253 :param sort_key: initial sorting of repos
254 :param simple: use SimpleCachedList - one without the SCM info
225 """
255 """
226 if all_repos is None:
256 if all_repos is None:
227 all_repos = self.sa.query(Repository)\
257 all_repos = self.sa.query(Repository)\
228 .filter(Repository.group_id == None)\
258 .filter(Repository.group_id == None)\
229 .order_by(func.lower(Repository.repo_name)).all()
259 .order_by(func.lower(Repository.repo_name)).all()
230
260 if simple:
231 repo_iter = CachedRepoList(all_repos, repos_path=self.repos_path,
261 repo_iter = SimpleCachedRepoList(all_repos,
232 order_by=sort_key)
262 repos_path=self.repos_path,
263 order_by=sort_key)
264 else:
265 repo_iter = CachedRepoList(all_repos,
266 repos_path=self.repos_path,
267 order_by=sort_key)
233
268
234 return repo_iter
269 return repo_iter
235
270
General Comments 0
You need to be logged in to leave comments. Login now