Mercurial > kallithea
comparison rhodecode/model/scm.py @ 791:06a98912325c beta
fixed bug when invalidation was making to many queries when there was no list of invalidation
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 29 Nov 2010 03:31:29 +0100 |
parents | 30d3161c6683 |
children | 4c16ed1eb699 |
comparison
equal
deleted
inserted
replaced
790:0142dac6f3c7 | 791:06a98912325c |
---|---|
119 """ | 119 """ |
120 if all_repos is None: | 120 if all_repos is None: |
121 all_repos = self.sa.query(Repository)\ | 121 all_repos = self.sa.query(Repository)\ |
122 .order_by(Repository.repo_name).all() | 122 .order_by(Repository.repo_name).all() |
123 | 123 |
124 #get the repositories that should be invalidated | |
124 invalidation_list = [str(x.cache_key) for x in \ | 125 invalidation_list = [str(x.cache_key) for x in \ |
125 self.sa.query(CacheInvalidation.cache_key)\ | 126 self.sa.query(CacheInvalidation.cache_key)\ |
126 .filter(CacheInvalidation.cache_active == False)\ | 127 .filter(CacheInvalidation.cache_active == False)\ |
127 .all()] | 128 .all()] |
128 | 129 |
156 | 157 |
157 def get(self, repo_name, invalidation_list=None): | 158 def get(self, repo_name, invalidation_list=None): |
158 """ | 159 """ |
159 Get's repository from given name, creates BackendInstance and | 160 Get's repository from given name, creates BackendInstance and |
160 propagates it's data from database with all additional information | 161 propagates it's data from database with all additional information |
162 | |
161 :param repo_name: | 163 :param repo_name: |
164 :param invalidation_list: if a invalidation list is given the get | |
165 method should not manually check if this repository needs | |
166 invalidation and just invalidate the repositories in list | |
167 | |
162 """ | 168 """ |
163 if not HasRepoPermissionAny('repository.read', 'repository.write', | 169 if not HasRepoPermissionAny('repository.read', 'repository.write', |
164 'repository.admin')(repo_name, 'get repo check'): | 170 'repository.admin')(repo_name, 'get repo check'): |
165 return | 171 return |
166 | 172 |
167 | 173 pre_invalidate = True |
174 if invalidation_list is not None: | |
175 pre_invalidate = repo_name in invalidation_list | |
176 | |
177 if pre_invalidate: | |
178 invalidate = self._should_invalidate(repo_name) | |
179 | |
180 if invalidate: | |
181 log.info('invalidating cache for repository %s', repo_name) | |
182 region_invalidate(_get_repo, None, repo_name) | |
183 self._mark_invalidated(invalidate) | |
184 | |
185 | |
186 #====================================================================== | |
187 # CACHE FUNCTION | |
188 #====================================================================== | |
168 @cache_region('long_term') | 189 @cache_region('long_term') |
169 def _get_repo(repo_name): | 190 def _get_repo(repo_name): |
170 | 191 |
171 repo_path = os.path.join(self.repos_path, repo_name) | 192 repo_path = os.path.join(self.repos_path, repo_name) |
172 | 193 |
200 if dbrepo.fork: | 221 if dbrepo.fork: |
201 make_transient(dbrepo.fork) | 222 make_transient(dbrepo.fork) |
202 | 223 |
203 repo.dbrepo = dbrepo | 224 repo.dbrepo = dbrepo |
204 return repo | 225 return repo |
205 | |
206 pre_invalidate = True | |
207 if invalidation_list: | |
208 pre_invalidate = repo_name in invalidation_list | |
209 | |
210 if pre_invalidate: | |
211 invalidate = self._should_invalidate(repo_name) | |
212 | |
213 if invalidate: | |
214 log.info('invalidating cache for repository %s', repo_name) | |
215 region_invalidate(_get_repo, None, repo_name) | |
216 self._mark_invalidated(invalidate) | |
217 | 226 |
218 return _get_repo(repo_name) | 227 return _get_repo(repo_name) |
219 | 228 |
220 | 229 |
221 | 230 |