##// 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 .filter(CacheInvalidation.cache_active == False)\
451 .filter(CacheInvalidation.cache_active == False)\
452 .scalar()
452 .scalar()
453
453
454 @property
455 def set_invalidate(self):
454 def set_invalidate(self):
456 """
455 """
457 set a cache for invalidation for this instance
456 set a cache for invalidation for this instance
@@ -476,18 +475,18 b' class Repository(Base, BaseModel):'
476 def _c(repo_name):
475 def _c(repo_name):
477 return self.__get_instance()
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 inv = self.invalidate
482 inv = self.invalidate
480 if inv is not None:
483 if inv is not None:
481 region_invalidate(_c, None, self.repo_name)
484 region_invalidate(_c, None, rn)
482 #update our cache
485 # update our cache
483 inv.cache_active = True
486 inv.cache_active = True
484 Session.add(inv)
487 Session.add(inv)
485 Session.commit()
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 return _c(rn)
490 return _c(rn)
492
491
493 def __get_instance(self):
492 def __get_instance(self):
@@ -66,10 +66,8 b' class RepoTemp(object):'
66
66
67 class CachedRepoList(object):
67 class CachedRepoList(object):
68
68
69 def __init__(self, db_repo_list, invalidation_list, repos_path,
69 def __init__(self, db_repo_list, repos_path, order_by=None):
70 order_by=None):
71 self.db_repo_list = db_repo_list
70 self.db_repo_list = db_repo_list
72 self.invalidation_list = invalidation_list
73 self.repos_path = repos_path
71 self.repos_path = repos_path
74 self.order_by = order_by
72 self.order_by = order_by
75 self.reversed = (order_by or '').startswith('-')
73 self.reversed = (order_by or '').startswith('-')
@@ -81,22 +79,9 b' class CachedRepoList(object):'
81 return '<%s (%s)>' % (self.__class__.__name__, self.__len__())
79 return '<%s (%s)>' % (self.__class__.__name__, self.__len__())
82
80
83 def __iter__(self):
81 def __iter__(self):
84 for db_repo in self.db_repo_list:
82 for dbr in self.db_repo_list:
85 dbr = db_repo
86
87 # invalidate the repo cache if needed before getting the
88 # scm instance
89
83
90 scm_invalidate = False
84 scmr = dbr.scm_instance_cached
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
100
85
101 #check permission at this level
86 #check permission at this level
102 if not HasRepoPermissionAny('repository.read',
87 if not HasRepoPermissionAny('repository.read',
@@ -201,14 +186,7 b' class ScmModel(BaseModel):'
201 .filter(Repository.group_id == None)\
186 .filter(Repository.group_id == None)\
202 .order_by(Repository.repo_name).all()
187 .order_by(Repository.repo_name).all()
203
188
204 #get the repositories that should be invalidated
189 repo_iter = CachedRepoList(all_repos, repos_path=self.repos_path,
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,
212 order_by=sort_key)
190 order_by=sort_key)
213
191
214 return repo_iter
192 return repo_iter
@@ -225,7 +203,7 b' class ScmModel(BaseModel):'
225 .filter(CacheInvalidation.cache_key == repo_name).scalar()
203 .filter(CacheInvalidation.cache_key == repo_name).scalar()
226
204
227 if cache:
205 if cache:
228 #mark this cache as inactive
206 # mark this cache as inactive
229 cache.cache_active = False
207 cache.cache_active = False
230 else:
208 else:
231 log.debug('cache key not found in invalidation db -> creating one')
209 log.debug('cache key not found in invalidation db -> creating one')
@@ -394,20 +372,3 b' class ScmModel(BaseModel):'
394 .scalar()
372 .scalar()
395
373
396 return ret
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