You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/07/08 00:11:26 UTC
[09/16] 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/db/6373
Commit: 664bd19f481cf11e34ddb667b509115e3504ea5e
Parents: 6e8e6f3
Author: Heith Seewald <hs...@slashdotmedia.com>
Authored: Mon Jun 29 16:07:56 2015 -0400
Committer: Heith Seewald <hs...@slashdotmedia.com>
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')