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/03 13:04:52 UTC

[1/3] allura git commit: [#7894] Fix issue where can_merge updated mod_date

Repository: allura
Updated Branches:
  refs/heads/master 0fd24ba4c -> 664bd19f4


[#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/master
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')


[2/3] allura git commit: [#7894] Move skip_mod_date into Allura

Posted by je...@apache.org.
[#7894] Move skip_mod_date into Allura


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/6e8e6f33
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/6e8e6f33
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/6e8e6f33

Branch: refs/heads/master
Commit: 6e8e6f33f5501290cbea052e99044a15a54beeeb
Parents: 23bcdc9
Author: Heith Seewald <hs...@slashdotmedia.com>
Authored: Mon Jun 29 14:36:55 2015 -0400
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Thu Jul 2 11:08:58 2015 -0400

----------------------------------------------------------------------
 Allura/allura/lib/utils.py        | 12 ++++++++++++
 Allura/allura/tests/test_utils.py |  8 ++++++++
 2 files changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/6e8e6f33/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 143868e..f812e2e 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -14,6 +14,7 @@
 #       KIND, either express or implied.  See the License for the
 #       specific language governing permissions and limitations
 #       under the License.
+from contextlib import contextmanager
 
 import time
 import string
@@ -21,6 +22,7 @@ import hashlib
 import binascii
 import logging.handlers
 import codecs
+from ming.odm import session
 import os.path
 import datetime
 import random
@@ -614,3 +616,13 @@ def clean_phone_number(number):
 def phone_number_hash(number):
     number = clean_phone_number(number)
     return hashlib.sha1(number).hexdigest()
+
+
+@contextmanager
+def skip_mod_date(model_cls):
+    skip_mod_date = getattr(session(model_cls)._get(), 'skip_mod_date', False)
+    session(model_cls)._get().skip_mod_date = True
+    try:
+        yield
+    finally:
+        session(model_cls)._get().skip_mod_date = skip_mod_date
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/allura/blob/6e8e6f33/Allura/allura/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_utils.py b/Allura/allura/tests/test_utils.py
index 5043e3d..39d61b3 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -21,6 +21,8 @@ import json
 import time
 import unittest
 import datetime as dt
+from ming.odm import session
+import model as M
 from os import path
 
 from webob import Request
@@ -323,3 +325,9 @@ def test_phone_number_hash():
     hash = utils.phone_number_hash
     assert_equal(hash('1234567890'), hash('+123 456:7890'))
     assert_not_equal(hash('1234567890'), hash('1234567891'))
+
+
+def test_skip_mod_date():
+    with utils.skip_mod_date(M.Artifact):
+        assert getattr(session(M.Artifact)._get(), 'skip_mod_date', None) == True
+    assert getattr(session(M.Artifact)._get(), 'skip_mod_date', None) == False
\ No newline at end of file


[3/3] allura git commit: [#7894] Merge request timestamps are no longer updated incorrectly

Posted by je...@apache.org.
[#7894] Merge request timestamps are no longer updated incorrectly


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/23bcdc9b
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/23bcdc9b
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/23bcdc9b

Branch: refs/heads/master
Commit: 23bcdc9b1dcee3c230fa49003902d22aaa72520f
Parents: 0fd24ba
Author: Heith Seewald <hs...@slashdotmedia.com>
Authored: Mon Jun 15 16:33:06 2015 -0400
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Thu Jul 2 11:08:58 2015 -0400

----------------------------------------------------------------------
 Allura/allura/model/repository.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/23bcdc9b/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index a3d574c..3f4799a 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -56,7 +56,8 @@ from .timeline import ActivityObject
 from .monq_model import MonQTask
 from .project import AppConfig
 from .session import main_doc_session
-from .session import repository_orm_session
+from .session import repository_orm_session, artifact_orm_session
+
 
 log = logging.getLogger(__name__)
 config = utils.ConfigProxy(
@@ -831,6 +832,9 @@ 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):