diff --git a/kallithea/lib/base.py b/kallithea/lib/base.py --- a/kallithea/lib/base.py +++ b/kallithea/lib/base.py @@ -323,14 +323,6 @@ class BaseVCSController(object): return '/'.join(data) - def _invalidate_cache(self, repo_name): - """ - Sets cache for this repository for invalidation on next access - - :param repo_name: full repo name, also a cache key - """ - ScmModel().mark_for_invalidation(repo_name) - def _check_permission(self, action, user, repo_name, ip_addr=None): """ Checks permissions using action (push/pull) user and repository @@ -630,23 +622,6 @@ class BaseRepoController(BaseController) raise webob.exc.HTTPBadRequest() -class WSGIResultCloseCallback(object): - """Wrap a WSGI result and let close call close after calling the - close method on the result. - """ - def __init__(self, result, close): - self._result = result - self._close = close - - def __iter__(self): - return iter(self._result) - - def close(self): - if hasattr(self._result, 'close'): - self._result.close() - self._close() - - @decorator.decorator def jsonify(func, *args, **kwargs): """Action decorator that formats output for JSON diff --git a/kallithea/lib/hooks.py b/kallithea/lib/hooks.py --- a/kallithea/lib/hooks.py +++ b/kallithea/lib/hooks.py @@ -148,9 +148,14 @@ def log_pull_action(ui, repo, **kwargs): def log_push_action(ui, repo, **kwargs): """ - Register that changes have been pushed. + Register that changes have been pushed - log it *and* invalidate caches. + Note: It is not only logging, but also the side effect invalidating cahes! + The function should perhaps be renamed. - Called as Mercurial hook changegroup.push_logger or from the Git post-receive hook calling handle_git_post_receive ... or from scm _handle_push + Called as Mercurial hook changegroup.push_logger or from the Git + post-receive hook calling handle_git_post_receive ... or from scm _handle_push. + + Revisions are passed in different hack-ish ways. """ ex = _extract_extras() @@ -180,6 +185,9 @@ def log_push_action(ui, repo, **kwargs): action = action_tmpl % ','.join(revs) action_logger(ex.username, action, ex.repository, ex.ip, commit=True) + from kallithea.model.scm import ScmModel + ScmModel().mark_for_invalidation(ex.repository) + # extension hook call from kallithea import EXTENSIONS callback = getattr(EXTENSIONS, 'PUSH_HOOK', None) diff --git a/kallithea/lib/middleware/simplegit.py b/kallithea/lib/middleware/simplegit.py --- a/kallithea/lib/middleware/simplegit.py +++ b/kallithea/lib/middleware/simplegit.py @@ -40,7 +40,7 @@ from kallithea.model.db import Ui from kallithea.lib.utils2 import safe_str, safe_unicode, fix_PATH, get_server_url, \ _set_extras -from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback, check_locking_state +from kallithea.lib.base import BaseVCSController, check_locking_state from kallithea.lib.utils import make_ui, is_valid_repo from kallithea.lib.exceptions import HTTPLockedRC from kallithea.lib.hooks import pull_lock_handling @@ -139,11 +139,7 @@ class SimpleGit(BaseVCSController): log.info('%s action on Git repo "%s" by "%s" from %s', action, str_repo_name, safe_str(user.username), ip_addr) app = self.__make_app(repo_name, repo_path, extras) - result = app(environ, start_response) - if action == 'push': - result = WSGIResultCloseCallback(result, - lambda: self._invalidate_cache(repo_name)) - return result + return app(environ, start_response) except HTTPLockedRC as e: log.debug('Locked, response %s: %s', e.code, e.title) return e(environ, start_response) diff --git a/kallithea/lib/middleware/simplehg.py b/kallithea/lib/middleware/simplehg.py --- a/kallithea/lib/middleware/simplehg.py +++ b/kallithea/lib/middleware/simplehg.py @@ -37,7 +37,7 @@ from webob.exc import HTTPNotFound, HTTP from kallithea.lib.utils2 import safe_str, safe_unicode, fix_PATH, get_server_url, \ _set_extras -from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback, check_locking_state +from kallithea.lib.base import BaseVCSController, check_locking_state from kallithea.lib.utils import make_ui, is_valid_repo, ui_sections from kallithea.lib.vcs.utils.hgcompat import RepoError, hgweb_mod from kallithea.lib.exceptions import HTTPLockedRC @@ -149,11 +149,7 @@ class SimpleHg(BaseVCSController): log.info('%s action on Mercurial repo "%s" by "%s" from %s', action, str_repo_name, safe_str(user.username), ip_addr) app = self.__make_app(repo_path, baseui, extras) - result = app(environ, start_response) - if action == 'push': - result = WSGIResultCloseCallback(result, - lambda: self._invalidate_cache(repo_name)) - return result + return app(environ, start_response) except RepoError as e: if str(e).find('not found') != -1: return HTTPNotFound()(environ, start_response)