Changeset - 8e2cd46f765b
[Not reviewed]
beta
0 4 0
Mads Kiilerich - 13 years ago 2013-04-03 15:56:12
madski@unity3d.com
Grafted from: 2bdc6d81f5a2
invalidate: encapsulate how key is generated from repo_name and kind
4 files changed with 20 insertions and 23 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/feed.py
Show inline comments
 
@@ -115,13 +115,13 @@ class FeedController(BaseRepoController)
 
        return map(safe_unicode, desc_msg)
 

	
 
    def atom(self, repo_name):
 
        """Produce an atom-1.0 feed via feedgenerator module"""
 

	
 
        @cache_region('long_term')
 
        def _get_feed_from_cache(key):
 
        def _get_feed_from_cache(key, kind):
 
            feed = Atom1Feed(
 
                 title=self.title % repo_name,
 
                 link=url('summary_home', repo_name=repo_name,
 
                          qualified=True),
 
                 description=self.description % repo_name,
 
                 language=self.language,
 
@@ -137,23 +137,23 @@ class FeedController(BaseRepoController)
 
                              pubdate=cs.date,
 
                              )
 

	
 
            response.content_type = feed.mime_type
 
            return feed.writeString('utf-8')
 

	
 
        key = repo_name + '_ATOM'
 
        valid = CacheInvalidation.test_and_set_valid(key)
 
        kind = 'ATOM'
 
        valid = CacheInvalidation.test_and_set_valid(repo_name, kind)
 
        if not valid:
 
            region_invalidate(_get_feed_from_cache, None, key)
 
        return _get_feed_from_cache(key)
 
            region_invalidate(_get_feed_from_cache, None, repo_name, kind)
 
        return _get_feed_from_cache(repo_name, kind)
 

	
 
    def rss(self, repo_name):
 
        """Produce an rss2 feed via feedgenerator module"""
 

	
 
        @cache_region('long_term')
 
        def _get_feed_from_cache(key):
 
        def _get_feed_from_cache(key, kind):
 
            feed = Rss201rev2Feed(
 
                title=self.title % repo_name,
 
                link=url('summary_home', repo_name=repo_name,
 
                         qualified=True),
 
                description=self.description % repo_name,
 
                language=self.language,
 
@@ -169,11 +169,11 @@ class FeedController(BaseRepoController)
 
                              pubdate=cs.date,
 
                             )
 

	
 
            response.content_type = feed.mime_type
 
            return feed.writeString('utf-8')
 

	
 
        key = repo_name + '_RSS'
 
        valid = CacheInvalidation.test_and_set_valid(key)
 
        kind = 'RSS'
 
        valid = CacheInvalidation.test_and_set_valid(repo_name, kind)
 
        if not valid:
 
            region_invalidate(_get_feed_from_cache, None, key)
 
        return _get_feed_from_cache(key)
 
            region_invalidate(_get_feed_from_cache, None, repo_name, kind)
 
        return _get_feed_from_cache(repo_name, kind)
rhodecode/controllers/summary.py
Show inline comments
 
@@ -89,13 +89,13 @@ class SummaryController(BaseRepoControll
 
        return download_l
 

	
 
    def __get_readme_data(self, db_repo):
 
        repo_name = db_repo.repo_name
 

	
 
        @cache_region('long_term')
 
        def _get_readme_from_cache(key):
 
        def _get_readme_from_cache(key, kind):
 
            readme_data = None
 
            readme_file = None
 
            log.debug('Looking for README file')
 
            try:
 
                # get's the landing revision! or tip if fails
 
                cs = db_repo.get_landing_changeset()
 
@@ -121,17 +121,17 @@ class SummaryController(BaseRepoControll
 
                pass
 
            except Exception:
 
                log.error(traceback.format_exc())
 

	
 
            return readme_data, readme_file
 

	
 
        key = repo_name + '_README'
 
        valid = CacheInvalidation.test_and_set_valid(key)
 
        kind = 'README'
 
        valid = CacheInvalidation.test_and_set_valid(repo_name, kind)
 
        if not valid:
 
            region_invalidate(_get_readme_from_cache, None, key)
 
        return _get_readme_from_cache(key)
 
            region_invalidate(_get_readme_from_cache, None, repo_name, kind)
 
        return _get_readme_from_cache(repo_name, kind)
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def index(self, repo_name):
 
        c.dbrepo = dbrepo = c.rhodecode_db_repo
rhodecode/lib/utils.py
Show inline comments
 
@@ -473,13 +473,13 @@ def repo2db_mapper(initial_repo_list, re
 
            if db_repo.repo_type == 'git':
 
                ScmModel().install_git_hook(db_repo.scm_instance)
 
        # during starting install all cache keys for all repositories in the
 
        # system, this will register all repos and multiple instances
 
        cache_key = CacheInvalidation._get_cache_key(name)
 
        log.debug("Creating invalidation cache key for %s: %s", name, cache_key)
 
        CacheInvalidation.test_and_set_valid(name)
 
        CacheInvalidation.test_and_set_valid(name, None)
 

	
 
    sa.commit()
 
    removed = []
 
    if remove_obsolete:
 
        # remove from database those repositories that are not in the filesystem
 
        for repo in sa.query(Repository).all():
rhodecode/model/db.py
Show inline comments
 
@@ -1183,13 +1183,13 @@ class Repository(Base, BaseModel):
 
    def scm_instance_cached(self, valid_cache_keys=None):
 
        @cache_region('long_term')
 
        def _c(repo_name):
 
            return self.__get_instance()
 
        rn = self.repo_name
 

	
 
        valid = CacheInvalidation.test_and_set_valid(rn, valid_cache_keys=valid_cache_keys)
 
        valid = CacheInvalidation.test_and_set_valid(rn, None, valid_cache_keys=valid_cache_keys)
 
        if not valid:
 
            log.debug('Cache for %s invalidated, getting new object' % (rn))
 
            region_invalidate(_c, None, rn)
 
        else:
 
            log.debug('Getting obj for %s from cache' % (rn))
 
        return _c(rn)
 
@@ -1825,28 +1825,25 @@ class CacheInvalidation(Base, BaseModel)
 
            Session().commit()
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            Session().rollback()
 

	
 
    @classmethod
 
    def test_and_set_valid(cls, key, valid_cache_keys=None):
 
    def test_and_set_valid(cls, repo_name, kind, valid_cache_keys=None):
 
        """
 
        Mark this cache key as active and currently cached.
 
        Return True if the existing cache registration still was valid.
 
        Return False to indicate that it had been invalidated and caches should be refreshed.
 
        """
 

	
 
        key = (repo_name + '_' + kind) if kind else repo_name
 
        cache_key = cls._get_cache_key(key)
 

	
 
        if valid_cache_keys and cache_key in valid_cache_keys:
 
            return True
 

	
 
        repo_name = key
 
        repo_name = remove_suffix(repo_name, '_README')
 
        repo_name = remove_suffix(repo_name, '_RSS')
 
        repo_name = remove_suffix(repo_name, '_ATOM')
 

	
 
        try:
 
            inv_obj = cls.query().filter(cls.cache_key == cache_key).scalar()
 
            if not inv_obj:
 
                inv_obj = CacheInvalidation(cache_key, repo_name)
 
            was_valid = inv_obj.cache_active
 
            inv_obj.cache_active = True
0 comments (0 inline, 0 general)