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:06:59 UTC

[1/4] allura git commit: [#7894] Move skip_mod_date into Allura

Repository: allura
Updated Branches:
  refs/heads/ib/7894 [created] a6638dd68


[#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/9db16337
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/9db16337
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/9db16337

Branch: refs/heads/ib/7894
Commit: 9db16337390bff78889b25380459607d32c17dff
Parents: bd03dc0
Author: Heith Seewald <hs...@slashdotmedia.com>
Authored: Mon Jun 29 14:36:55 2015 -0400
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Jul 2 08:33:44 2015 +0000

----------------------------------------------------------------------
 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/9db16337/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/9db16337/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


[4/4] allura git commit: [#7894] Remove unused imports

Posted by je...@apache.org.
[#7894] Remove unused imports


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

Branch: refs/heads/ib/7894
Commit: a6638dd68b61c0194424465b5fd59aec74df31de
Parents: 59f11d7
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Jul 2 08:38:09 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Jul 2 08:38:09 2015 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py | 2 +-
 Allura/allura/tasks/repo_tasks.py | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/a6638dd6/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index b3c60b7..d1ac4fe 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -56,7 +56,7 @@ 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, artifact_orm_session
+from .session import repository_orm_session
 
 
 log = logging.getLogger(__name__)

http://git-wip-us.apache.org/repos/asf/allura/blob/a6638dd6/Allura/allura/tasks/repo_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/repo_tasks.py b/Allura/allura/tasks/repo_tasks.py
index 9ea9fd0..e44ea94 100644
--- a/Allura/allura/tasks/repo_tasks.py
+++ b/Allura/allura/tasks/repo_tasks.py
@@ -24,7 +24,6 @@ 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


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

Branch: refs/heads/ib/7894
Commit: bd03dc0c0bc47b8e914dfcb8b5bca42077b570cb
Parents: 14edf90
Author: Heith Seewald <hs...@slashdotmedia.com>
Authored: Mon Jun 15 16:33:06 2015 -0400
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Jul 2 08:33:44 2015 +0000

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


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


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

Posted by je...@apache.org.
[#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