You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/07/02 11:07:01 UTC

[3/4] 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/59f11d73
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/59f11d73
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/59f11d73

Branch: refs/heads/ib/7894
Commit: 59f11d738b467a0afedb2ad3f43b5d012bfbab18
Parents: 9db1633
Author: Heith Seewald <hs...@slashdotmedia.com>
Authored: Mon Jun 29 16:07:56 2015 -0400
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Jul 2 08:33:45 2015 +0000

----------------------------------------------------------------------
 Allura/allura/lib/utils.py        | 16 ++++++++++++++++
 Allura/allura/model/repository.py |  8 ++++----
 Allura/allura/tasks/repo_tasks.py |  1 +
 3 files changed, 21 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/59f11d73/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/59f11d73/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/59f11d73/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