# HG changeset patch # User Marcin Kuzminski # Date 1353686370 -3600 # Node ID 00498b3e4c887b053574bb11eb05d307119f4cd9 # Parent e85380f05a5e0e01d810f8194b5f95a90f7dce27 Cleaned the way cache keys are invalidated should fix issue #504 RhodeCode is showing different versions of README on different summary page loads diff -r e85380f05a5e -r 00498b3e4c88 rhodecode/lib/utils.py --- a/rhodecode/lib/utils.py Fri Nov 23 13:27:34 2012 +0100 +++ b/rhodecode/lib/utils.py Fri Nov 23 16:59:30 2012 +0100 @@ -448,8 +448,10 @@ # during starting install all cache keys for all repositories in the # system, this will register all repos and multiple instances key, _prefix, _org_key = CacheInvalidation._get_key(name) - log.debug("Creating a cache key for %s instance_id:`%s`" % (name, _prefix)) - CacheInvalidation._get_or_create_key(key, _prefix, _org_key, commit=False) + CacheInvalidation.invalidate(name) + log.debug("Creating a cache key for %s instance_id=>`%s`" + % (name, _prefix or '-')) + sa.commit() removed = [] if remove_obsolete: diff -r e85380f05a5e -r 00498b3e4c88 rhodecode/model/db.py --- a/rhodecode/model/db.py Fri Nov 23 13:27:34 2012 +0100 +++ b/rhodecode/model/db.py Fri Nov 23 16:59:30 2012 +0100 @@ -937,7 +937,7 @@ """ set a cache for invalidation for this instance """ - CacheInvalidation.set_invalidate(self.repo_name) + CacheInvalidation.set_invalidate(repo_name=self.repo_name) @LazyProperty def scm_instance(self): @@ -1438,25 +1438,27 @@ """ import rhodecode prefix = '' + org_key = key iid = rhodecode.CONFIG.get('instance_id') if iid: prefix = iid - #remove specific suffixes like _README or _RSS - key = remove_suffix(key, '_README') - key = remove_suffix(key, '_RSS') - key = remove_suffix(key, '_ATOM') - return "%s%s" % (prefix, key), prefix, key + + return "%s%s" % (prefix, key), prefix, org_key @classmethod def get_by_key(cls, key): return cls.query().filter(cls.cache_key == key).scalar() @classmethod - def _get_or_create_key(cls, key, prefix, org_key, commit=True): + def get_by_repo_name(cls, repo_name): + return cls.query().filter(cls.cache_args == repo_name).all() + + @classmethod + def _get_or_create_key(cls, key, repo_name, commit=True): inv_obj = Session().query(cls).filter(cls.cache_key == key).scalar() if not inv_obj: try: - inv_obj = CacheInvalidation(key, org_key) + inv_obj = CacheInvalidation(key, repo_name) Session().add(inv_obj) if commit: Session().commit() @@ -1474,30 +1476,38 @@ :param key: """ + repo_name = key + repo_name = remove_suffix(repo_name, '_README') + repo_name = remove_suffix(repo_name, '_RSS') + repo_name = remove_suffix(repo_name, '_ATOM') + # adds instance prefix key, _prefix, _org_key = cls._get_key(key) - inv = cls._get_or_create_key(key, _prefix, _org_key) + inv = cls._get_or_create_key(key, repo_name) if inv and inv.cache_active is False: return inv @classmethod - def set_invalidate(cls, key): + def set_invalidate(cls, key=None, repo_name=None): """ - Mark this Cache key for invalidation + Mark this Cache key for invalidation, either by key or whole + cache sets based on repo_name :param key: """ + if key: + key, _prefix, _org_key = cls._get_key(key) + inv_objs = Session().query(cls).filter(cls.cache_key == key).all() + elif repo_name: + inv_objs = Session().query(cls).filter(cls.cache_args == repo_name).all() - key, _prefix, _org_key = cls._get_key(key) - inv_objs = Session().query(cls).filter(cls.cache_args == _org_key).all() - log.debug('marking %s key[s] %s for invalidation' % (len(inv_objs), - _org_key)) + log.debug('marking %s key[s] for invalidation based on key=%s,repo_name=%s' + % (len(inv_objs), key, repo_name)) try: for inv_obj in inv_objs: - if inv_obj: - inv_obj.cache_active = False - + print inv_obj + inv_obj.cache_active = False Session().add(inv_obj) Session().commit() except Exception: diff -r e85380f05a5e -r 00498b3e4c88 rhodecode/model/scm.py --- a/rhodecode/model/scm.py Fri Nov 23 13:27:34 2012 +0100 +++ b/rhodecode/model/scm.py Fri Nov 23 16:59:30 2012 +0100 @@ -291,7 +291,7 @@ :param repo_name: this repo that should invalidation take place """ - CacheInvalidation.set_invalidate(repo_name) + CacheInvalidation.set_invalidate(repo_name=repo_name) def toggle_following_repo(self, follow_repo_id, user_id): diff -r e85380f05a5e -r 00498b3e4c88 rhodecode/public/css/style.css --- a/rhodecode/public/css/style.css Fri Nov 23 13:27:34 2012 +0100 +++ b/rhodecode/public/css/style.css Fri Nov 23 16:59:30 2012 +0100 @@ -1627,6 +1627,7 @@ background: #eee; border-bottom: 1px solid #ddd; padding: 5px 0px 5px 5px; + text-align: left; } #content div.box table th.left { diff -r e85380f05a5e -r 00498b3e4c88 rhodecode/templates/admin/repos/repo_edit.html --- a/rhodecode/templates/admin/repos/repo_edit.html Fri Nov 23 13:27:34 2012 +0100 +++ b/rhodecode/templates/admin/repos/repo_edit.html Fri Nov 23 16:59:30 2012 +0100 @@ -196,11 +196,20 @@
${_('List of cached values')} -