##// END OF EJS Templates
- #347 when running multiple RhodeCode instances, properly invalidates cache...
marcink -
r2147:d25bd432 beta
parent child Browse files
Show More
@@ -28,6 +28,8 b' news'
28 - #402 removed group prefix from repository name when listing repositories
28 - #402 removed group prefix from repository name when listing repositories
29 inside a group
29 inside a group
30 - added gravatars into permission view and permissions autocomplete
30 - added gravatars into permission view and permissions autocomplete
31 - #347 when running multiple RhodeCode instances, properly invalidates cache
32 for all registered servers
31
33
32 fixes
34 fixes
33 +++++
35 +++++
@@ -51,7 +51,8 b' from rhodecode.lib.caching_query import '
51
51
52 from rhodecode.model import meta
52 from rhodecode.model import meta
53 from rhodecode.model.db import Repository, User, RhodeCodeUi, \
53 from rhodecode.model.db import Repository, User, RhodeCodeUi, \
54 UserLog, RepoGroup, RhodeCodeSetting, UserRepoGroupToPerm
54 UserLog, RepoGroup, RhodeCodeSetting, UserRepoGroupToPerm,\
55 CacheInvalidation
55 from rhodecode.model.meta import Session
56 from rhodecode.model.meta import Session
56 from rhodecode.model.repos_group import ReposGroupModel
57 from rhodecode.model.repos_group import ReposGroupModel
57 from rhodecode.lib.utils2 import safe_str, safe_unicode
58 from rhodecode.lib.utils2 import safe_str, safe_unicode
@@ -452,13 +453,19 b' def repo2db_mapper(initial_repo_list, re'
452 sa.commit()
453 sa.commit()
453 removed = []
454 removed = []
454 if remove_obsolete:
455 if remove_obsolete:
455 #remove from database those repositories that are not in the filesystem
456 # remove from database those repositories that are not in the filesystem
456 for repo in sa.query(Repository).all():
457 for repo in sa.query(Repository).all():
457 if repo.repo_name not in initial_repo_list.keys():
458 if repo.repo_name not in initial_repo_list.keys():
459 log.debug("Removing non existing repository found in db %s" %
460 repo.repo_name)
458 removed.append(repo.repo_name)
461 removed.append(repo.repo_name)
459 sa.delete(repo)
462 sa.delete(repo)
460 sa.commit()
463 sa.commit()
461
464
465 # clear cache keys
466 log.debug("Clearing cache keys now...")
467 CacheInvalidation.clear_cache()
468 sa.commit()
462 return added, removed
469 return added, removed
463
470
464
471
@@ -1042,11 +1042,14 b' class CacheInvalidation(Base, BaseModel)'
1042 def __repr__(self):
1042 def __repr__(self):
1043 return "<%s('%s:%s')>" % (self.__class__.__name__,
1043 return "<%s('%s:%s')>" % (self.__class__.__name__,
1044 self.cache_id, self.cache_key)
1044 self.cache_id, self.cache_key)
1045 @classmethod
1046 def clear_cache(cls):
1047 cls.query().delete()
1045
1048
1046 @classmethod
1049 @classmethod
1047 def _get_key(cls, key):
1050 def _get_key(cls, key):
1048 """
1051 """
1049 Wrapper for generating a key
1052 Wrapper for generating a key, together with a prefix
1050
1053
1051 :param key:
1054 :param key:
1052 """
1055 """
@@ -1055,12 +1058,25 b' class CacheInvalidation(Base, BaseModel)'
1055 iid = rhodecode.CONFIG.get('instance_id')
1058 iid = rhodecode.CONFIG.get('instance_id')
1056 if iid:
1059 if iid:
1057 prefix = iid
1060 prefix = iid
1058 return "%s%s" % (prefix, key)
1061 return "%s%s" % (prefix, key), prefix, key.rstrip('_README')
1059
1062
1060 @classmethod
1063 @classmethod
1061 def get_by_key(cls, key):
1064 def get_by_key(cls, key):
1062 return cls.query().filter(cls.cache_key == key).scalar()
1065 return cls.query().filter(cls.cache_key == key).scalar()
1063
1066
1067 @classmethod
1068 def _get_or_create_key(cls, key, prefix, org_key):
1069 inv_obj = Session.query(cls).filter(cls.cache_key == key).scalar()
1070 if not inv_obj:
1071 try:
1072 inv_obj = CacheInvalidation(key, org_key)
1073 Session.add(inv_obj)
1074 Session.commit()
1075 except Exception:
1076 log.error(traceback.format_exc())
1077 Session.rollback()
1078 return inv_obj
1079
1064 @classmethod
1080 @classmethod
1065 def invalidate(cls, key):
1081 def invalidate(cls, key):
1066 """
1082 """
@@ -1070,10 +1086,12 b' class CacheInvalidation(Base, BaseModel)'
1070
1086
1071 :param key:
1087 :param key:
1072 """
1088 """
1073 return cls.query()\
1089
1074 .filter(CacheInvalidation.cache_key == key)\
1090 key, _prefix, _org_key = cls._get_key(key)
1075 .filter(CacheInvalidation.cache_active == False)\
1091 inv = cls._get_or_create_key(key, _prefix, _org_key)
1076 .scalar()
1092
1093 if inv and inv.cache_active is False:
1094 return inv
1077
1095
1078 @classmethod
1096 @classmethod
1079 def set_invalidate(cls, key):
1097 def set_invalidate(cls, key):
@@ -1083,17 +1101,16 b' class CacheInvalidation(Base, BaseModel)'
1083 :param key:
1101 :param key:
1084 """
1102 """
1085
1103
1086 log.debug('marking %s for invalidation' % key)
1104 key, _prefix, _org_key = cls._get_key(key)
1087 inv_obj = Session.query(cls)\
1105 inv_objs = Session.query(cls).filter(cls.cache_args == _org_key).all()
1088 .filter(cls.cache_key == key).scalar()
1106 log.debug('marking %s key[s] %s for invalidation' % (len(inv_objs),
1089 if inv_obj:
1107 _org_key))
1090 inv_obj.cache_active = False
1108 try:
1091 else:
1109 for inv_obj in inv_objs:
1092 log.debug('cache key not found in invalidation db -> creating one')
1110 if inv_obj:
1093 inv_obj = CacheInvalidation(key)
1111 inv_obj.cache_active = False
1094
1112
1095 try:
1113 Session.add(inv_obj)
1096 Session.add(inv_obj)
1097 Session.commit()
1114 Session.commit()
1098 except Exception:
1115 except Exception:
1099 log.error(traceback.format_exc())
1116 log.error(traceback.format_exc())
@@ -235,13 +235,13 b' class ScmModel(BaseModel):'
235 return group_iter
235 return group_iter
236
236
237 def mark_for_invalidation(self, repo_name):
237 def mark_for_invalidation(self, repo_name):
238 """Puts cache invalidation task into db for
238 """
239 Puts cache invalidation task into db for
239 further global cache invalidation
240 further global cache invalidation
240
241
241 :param repo_name: this repo that should invalidation take place
242 :param repo_name: this repo that should invalidation take place
242 """
243 """
243 CacheInvalidation.set_invalidate(repo_name)
244 CacheInvalidation.set_invalidate(repo_name)
244 CacheInvalidation.set_invalidate(repo_name + "_README")
245
245
246 def toggle_following_repo(self, follow_repo_id, user_id):
246 def toggle_following_repo(self, follow_repo_id, user_id):
247
247
General Comments 0
You need to be logged in to leave comments. Login now