Return-Path: X-Original-To: apmail-allura-commits-archive@www.apache.org Delivered-To: apmail-allura-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8B05C18358 for ; Thu, 2 Jul 2015 15:09:17 +0000 (UTC) Received: (qmail 51963 invoked by uid 500); 2 Jul 2015 15:09:17 -0000 Delivered-To: apmail-allura-commits-archive@allura.apache.org Received: (qmail 51902 invoked by uid 500); 2 Jul 2015 15:09:17 -0000 Mailing-List: contact commits-help@allura.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@allura.apache.org Delivered-To: mailing list commits@allura.apache.org Received: (qmail 51485 invoked by uid 99); 2 Jul 2015 15:09:17 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jul 2015 15:09:17 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F3D40E3660; Thu, 2 Jul 2015 15:09:16 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: heiths@apache.org To: commits@allura.apache.org Date: Thu, 02 Jul 2015 15:09:38 -0000 Message-Id: <47bf7ddb5fb24d3c823d0bd1eeb07b23@git.apache.org> In-Reply-To: <58580311e9a34e8b9331d612c87de32d@git.apache.org> References: <58580311e9a34e8b9331d612c87de32d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [23/23] allura git commit: [#7894] Fix issue where can_merge updated mod_date [#7894] Fix issue where can_merge updated mod_date Project: http://git-wip-us.apache.org/repos/asf/allura/repo Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/664bd19f Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/664bd19f Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/664bd19f Branch: refs/heads/hs/7894 Commit: 664bd19f481cf11e34ddb667b509115e3504ea5e Parents: 6e8e6f3 Author: Heith Seewald Authored: Mon Jun 29 16:07:56 2015 -0400 Committer: Heith Seewald Committed: Thu Jul 2 11:08:58 2015 -0400 ---------------------------------------------------------------------- Allura/allura/lib/utils.py | 16 ++++++++++++++++ Allura/allura/model/repository.py | 8 ++++---- Allura/allura/tasks/repo_tasks.py | 1 + Allura/allura/tests/model/test_repo.py | 3 ++- 4 files changed, 23 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/allura/blob/664bd19f/Allura/allura/lib/utils.py ---------------------------------------------------------------------- diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py index f812e2e..b00d7c1 100644 --- a/Allura/allura/lib/utils.py +++ b/Allura/allura/lib/utils.py @@ -620,6 +620,22 @@ def phone_number_hash(number): @contextmanager def skip_mod_date(model_cls): + """ Avoids updating 'mod_date' + + Useful for saving cache on a model and things like that. + + .. note:: This only works when the changes made to the model are flushed. + + :Example: + + from allura import model as M + key = self.can_merge_cache_key() + with utils.skip_mod_date(M.MergeRequest): + self.can_merge_cache[key] = val + session(self).flush(self) + + :param model_cls: The model *class* being updated. + """ skip_mod_date = getattr(session(model_cls)._get(), 'skip_mod_date', False) session(model_cls)._get().skip_mod_date = True try: http://git-wip-us.apache.org/repos/asf/allura/blob/664bd19f/Allura/allura/model/repository.py ---------------------------------------------------------------------- diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py index 3f4799a..b3c60b7 100644 --- a/Allura/allura/model/repository.py +++ b/Allura/allura/model/repository.py @@ -832,9 +832,6 @@ class MergeRequest(VersionedArtifact, ActivityObject): return False if self.app.config.options.get('merge_disabled'): return False - - _session = artifact_orm_session._get() - _session.skip_mod_date = True return True def can_merge_cache_key(self): @@ -853,8 +850,11 @@ class MergeRequest(VersionedArtifact, ActivityObject): return self.can_merge_cache.get(key) def set_can_merge_cache(self, val): + from allura import model as M key = self.can_merge_cache_key() - self.can_merge_cache[key] = val + with utils.skip_mod_date(M.MergeRequest): + self.can_merge_cache[key] = val + session(self).flush(self) def can_merge(self): """ http://git-wip-us.apache.org/repos/asf/allura/blob/664bd19f/Allura/allura/tasks/repo_tasks.py ---------------------------------------------------------------------- diff --git a/Allura/allura/tasks/repo_tasks.py b/Allura/allura/tasks/repo_tasks.py index e44ea94..9ea9fd0 100644 --- a/Allura/allura/tasks/repo_tasks.py +++ b/Allura/allura/tasks/repo_tasks.py @@ -24,6 +24,7 @@ from ming.odm import session from allura.lib.decorators import task from allura.lib.repository import RepositoryApp +from allura.lib.utils import skip_mod_date @task http://git-wip-us.apache.org/repos/asf/allura/blob/664bd19f/Allura/allura/tests/model/test_repo.py ---------------------------------------------------------------------- diff --git a/Allura/allura/tests/model/test_repo.py b/Allura/allura/tests/model/test_repo.py index f71ad71..1f6ec3c 100644 --- a/Allura/allura/tests/model/test_repo.py +++ b/Allura/allura/tests/model/test_repo.py @@ -808,5 +808,6 @@ class TestMergeRequest(object): assert_equal(self.mr.can_merge_task_status(), None) repo_tasks.can_merge.post(self.mr._id) assert_equal(self.mr.can_merge_task_status(), 'ready') - M.MonQTask.run_ready() + with mock.patch('allura.model.repository.MergeRequest.set_can_merge_cache'): + M.MonQTask.run_ready() assert_equal(self.mr.can_merge_task_status(), 'complete')