Changeset - d6a56c5a77fc
[Not reviewed]
default
0 2 0
Mads Kiilerich - 6 years ago 2019-10-21 00:17:28
mads@kiilerich.com
Grafted from: f7042eaa7afd
caching: invalidate Repository cache of README and RSS based on latest revision hash in its .changeset_cache

Avoid using the the more heavy and complex CacheInvalidation.

Note that raw_id only is passed to the getter function as cache key, in order
to make sure new data is retrieved whenever the repo changes.
2 files changed with 6 insertions and 16 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/feed.py
Show inline comments
 
@@ -28,7 +28,7 @@ Original author and date, and relevant c
 

	
 
import logging
 

	
 
from beaker.cache import cache_region, region_invalidate
 
from beaker.cache import cache_region
 
from tg import response
 
from tg import tmpl_context as c
 
from tg.i18n import ugettext as _
 
@@ -40,7 +40,6 @@ from kallithea.lib.auth import HasRepoPe
 
from kallithea.lib.base import BaseRepoController
 
from kallithea.lib.diffs import DiffProcessor
 
from kallithea.lib.utils2 import safe_int, safe_unicode, str2bool
 
from kallithea.model.db import CacheInvalidation
 

	
 

	
 
log = logging.getLogger(__name__)
 
@@ -130,10 +129,7 @@ class FeedController(BaseRepoController)
 
            return feed.writeString('utf-8')
 

	
 
        kind = 'ATOM'
 
        valid = CacheInvalidation.test_and_set_valid(repo_name, kind)
 
        if not valid:
 
            region_invalidate(_get_feed_from_cache, None, '_get_feed_from_cache', repo_name, kind)
 
        return _get_feed_from_cache(repo_name, kind)
 
        return _get_feed_from_cache(repo_name, kind, c.db_repo.changeset_cache.get('raw_id'))
 

	
 
    def rss(self, repo_name):
 
        """Produce an rss2 feed via feedgenerator module"""
 
@@ -162,7 +158,4 @@ class FeedController(BaseRepoController)
 
            return feed.writeString('utf-8')
 

	
 
        kind = 'RSS'
 
        valid = CacheInvalidation.test_and_set_valid(repo_name, kind)
 
        if not valid:
 
            region_invalidate(_get_feed_from_cache, None, '_get_feed_from_cache', repo_name, kind)
 
        return _get_feed_from_cache(repo_name, kind)
 
        return _get_feed_from_cache(repo_name, kind, c.db_repo.changeset_cache.get('raw_id'))
kallithea/controllers/summary.py
Show inline comments
 
@@ -32,7 +32,7 @@ import traceback
 
from datetime import date, timedelta
 
from time import mktime
 

	
 
from beaker.cache import cache_region, region_invalidate
 
from beaker.cache import cache_region
 
from tg import request
 
from tg import tmpl_context as c
 
from tg.i18n import ugettext as _
 
@@ -49,7 +49,7 @@ from kallithea.lib.utils2 import safe_in
 
from kallithea.lib.vcs.backends.base import EmptyChangeset
 
from kallithea.lib.vcs.exceptions import ChangesetError, EmptyRepositoryError, NodeDoesNotExistError
 
from kallithea.lib.vcs.nodes import FileNode
 
from kallithea.model.db import CacheInvalidation, Statistics
 
from kallithea.model.db import Statistics
 

	
 

	
 
log = logging.getLogger(__name__)
 
@@ -97,10 +97,7 @@ class SummaryController(BaseRepoControll
 
            return readme_data, readme_file
 

	
 
        kind = 'README'
 
        valid = CacheInvalidation.test_and_set_valid(repo_name, kind)
 
        if not valid:
 
            region_invalidate(_get_readme_from_cache, None, '_get_readme_from_cache', repo_name, kind)
 
        return _get_readme_from_cache(repo_name, kind)
 
        return _get_readme_from_cache(repo_name, kind, c.db_repo.changeset_cache.get('raw_id'))
 

	
 
    @LoginRequired(allow_default_user=True)
 
    @HasRepoPermissionLevelDecorator('read')
0 comments (0 inline, 0 general)