incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/2] git commit: [#5023] change mailbox find_and_modify loop to be a single query loop
Date Wed, 03 Oct 2012 21:55:15 GMT
Updated Branches:
  refs/heads/db/5023 abff15a56 -> 80934a197 (forced update)


[#5023] change mailbox find_and_modify loop to be a single query loop


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

Branch: refs/heads/db/5023
Commit: 80934a1978d55f721b57616e01f142711cea4233
Parents: a67afef
Author: Dave Brondsema <dbrondsema@geek.net>
Authored: Wed Oct 3 20:36:51 2012 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Wed Oct 3 21:54:45 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/utils.py                     |    7 +++++++
 Allura/allura/model/notification.py            |   11 ++++++++---
 Allura/allura/tests/model/test_notification.py |    5 ++---
 3 files changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/80934a19/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 38383c5..2fb0390 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -446,3 +446,10 @@ def is_text_file(file):
     if ("text" in msg) or ("empty" in msg):
         return True
     return False
+
+
+def take_while_true(source):
+    x = source()
+    while x:
+        yield x
+        x = source()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/80934a19/Allura/allura/model/notification.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
index 704bf18..da98389 100644
--- a/Allura/allura/model/notification.py
+++ b/Allura/allura/model/notification.py
@@ -31,6 +31,7 @@ from ming.orm.declarative import MappedClass
 
 from allura.lib import helpers as h
 from allura.lib import security
+from allura.lib.utils import take_while_true
 import allura.tasks.mail_tasks
 
 from .session import main_orm_session, project_orm_session
@@ -450,15 +451,19 @@ class Mailbox(MappedClass):
         q_digest = dict(
             type={'$in': ['digest', 'summary']},
             next_scheduled={'$lt':now})
-        for mbox in cls.query.find(q_direct):
-            mbox = cls.query.find_and_modify(
-                query=dict(_id=mbox._id),
+
+        def find_and_modify_direct_mbox():
+            return cls.query.find_and_modify(
+                query=q_direct,
                 update={'$set': dict(
                             queue=[],
                             queue_empty=True,
                         )},
                 new=False)
+
+        for mbox in take_while_true(find_and_modify_direct_mbox):
             mbox.fire(now)
+
         for mbox in cls.query.find(q_digest):
             next_scheduled = now
             if mbox.frequency.unit == 'day':

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/80934a19/Allura/allura/tests/model/test_notification.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_notification.py b/Allura/allura/tests/model/test_notification.py
index d59fc1c..7cca4ab 100644
--- a/Allura/allura/tests/model/test_notification.py
+++ b/Allura/allura/tests/model/test_notification.py
@@ -108,7 +108,7 @@ class TestPostNotifications(unittest.TestCase):
         assert_equal(M.Notification.query.get()['from_address'], '"Test Admin" <test-admin@users.localhost>')
         assert_equal(M.Mailbox.query.find().count(), 2)
 
-        M.MonQTask.run_ready()  # sends the notification out into "mailboxes"
+        M.MonQTask.run_ready()  # sends the notification out into "mailboxes", and from mailboxes
into email tasks
         mboxes = M.Mailbox.query.find().all()
         assert_equal(len(mboxes), 2)
         assert_equal(len(mboxes[0].queue), 1)
@@ -116,7 +116,6 @@ class TestPostNotifications(unittest.TestCase):
         assert_equal(len(mboxes[1].queue), 1)
         assert not mboxes[1].queue_empty
 
-        M.Mailbox.fire_ready()
         email_tasks = M.MonQTask.query.find({'state': 'ready'}).all()
         assert_equal(len(email_tasks), 2)  # make sure both subscribers will get an email
 
@@ -203,7 +202,7 @@ class TestSubscriptionTypes(unittest.TestCase):
 
     def test_message(self):
         self._test_message()
-        
+
         self.setUp()
         self._test_message()
 


Mime
View raw message