##// END OF EJS Templates
fixed some issues with cache invalidation, and simplified invalidation codes
marcink -
r1428:e5467730 beta
parent child Browse files
Show More
@@ -451,7 +451,6 b' class Repository(Base, BaseModel):'
451 451 .filter(CacheInvalidation.cache_active == False)\
452 452 .scalar()
453 453
454 @property
455 454 def set_invalidate(self):
456 455 """
457 456 set a cache for invalidation for this instance
@@ -476,18 +475,18 b' class Repository(Base, BaseModel):'
476 475 def _c(repo_name):
477 476 return self.__get_instance()
478 477
478 # TODO: remove this trick when beaker 1.6 is released
479 # and have fixed this issue with not supporting unicode keys
480 rn = safe_str(self.repo_name)
481
479 482 inv = self.invalidate
480 483 if inv is not None:
481 region_invalidate(_c, None, self.repo_name)
482 #update our cache
484 region_invalidate(_c, None, rn)
485 # update our cache
483 486 inv.cache_active = True
484 487 Session.add(inv)
485 488 Session.commit()
486 489
487 # TODO: remove this trick when beaker 1.6 is released
488 # and have fixed this issue
489 rn = safe_str(self.repo_name)
490
491 490 return _c(rn)
492 491
493 492 def __get_instance(self):
@@ -66,10 +66,8 b' class RepoTemp(object):'
66 66
67 67 class CachedRepoList(object):
68 68
69 def __init__(self, db_repo_list, invalidation_list, repos_path,
70 order_by=None):
69 def __init__(self, db_repo_list, repos_path, order_by=None):
71 70 self.db_repo_list = db_repo_list
72 self.invalidation_list = invalidation_list
73 71 self.repos_path = repos_path
74 72 self.order_by = order_by
75 73 self.reversed = (order_by or '').startswith('-')
@@ -81,22 +79,9 b' class CachedRepoList(object):'
81 79 return '<%s (%s)>' % (self.__class__.__name__, self.__len__())
82 80
83 81 def __iter__(self):
84 for db_repo in self.db_repo_list:
85 dbr = db_repo
86
87 # invalidate the repo cache if needed before getting the
88 # scm instance
82 for dbr in self.db_repo_list:
89 83
90 scm_invalidate = False
91 if self.invalidation_list is not None:
92 scm_invalidate = dbr.repo_name in self.invalidation_list
93
94 if scm_invalidate:
95 log.info('invalidating cache for repository %s',
96 dbr.repo_name)
97 db_repo.set_invalidate
98
99 scmr = db_repo.scm_instance_cached
84 scmr = dbr.scm_instance_cached
100 85
101 86 #check permission at this level
102 87 if not HasRepoPermissionAny('repository.read',
@@ -201,14 +186,7 b' class ScmModel(BaseModel):'
201 186 .filter(Repository.group_id == None)\
202 187 .order_by(Repository.repo_name).all()
203 188
204 #get the repositories that should be invalidated
205 invalidation_list = [str(x.cache_key) for x in \
206 self.sa.query(CacheInvalidation.cache_key)\
207 .filter(CacheInvalidation.cache_active == False)\
208 .all()]
209
210 repo_iter = CachedRepoList(all_repos, invalidation_list,
211 repos_path=self.repos_path,
189 repo_iter = CachedRepoList(all_repos, repos_path=self.repos_path,
212 190 order_by=sort_key)
213 191
214 192 return repo_iter
@@ -225,7 +203,7 b' class ScmModel(BaseModel):'
225 203 .filter(CacheInvalidation.cache_key == repo_name).scalar()
226 204
227 205 if cache:
228 #mark this cache as inactive
206 # mark this cache as inactive
229 207 cache.cache_active = False
230 208 else:
231 209 log.debug('cache key not found in invalidation db -> creating one')
@@ -394,20 +372,3 b' class ScmModel(BaseModel):'
394 372 .scalar()
395 373
396 374 return ret
397
398 def _mark_invalidated(self, cache_key):
399 """ Marks all occurrences of cache to invalidation as already
400 invalidated
401
402 :param cache_key:
403 """
404
405 if cache_key:
406 log.debug('marking %s as already invalidated', cache_key)
407 try:
408 cache_key.cache_active = True
409 self.sa.add(cache_key)
410 self.sa.commit()
411 except (DatabaseError,):
412 log.error(traceback.format_exc())
413 self.sa.rollback()
General Comments 0
You need to be logged in to leave comments. Login now