incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [22/50] git commit: [#6545] remove old indexes and code; add 'timestamp' to discussion_id,status index
Date Tue, 17 Sep 2013 19:57:49 GMT
[#6545] remove old indexes and code; add 'timestamp' to discussion_id,status index

* Message's index on timestamp was added in 76e8541c for stats on ticket comments,
  our new index is a better fit
* Message's slug & parent_id indexes were added in ebb201de for now-unused
  replies() and descendants() methods


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

Branch: refs/heads/cj/6422
Commit: 58083948e5611ff57a899ced570718f71c0366fd
Parents: 28d8c31
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Wed Sep 4 13:58:06 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Tue Sep 10 14:31:48 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/artifact.py              | 25 -----------------------
 Allura/allura/model/discuss.py               | 17 +++++++--------
 Allura/allura/tests/model/test_artifact.py   | 18 ----------------
 Allura/allura/tests/model/test_discussion.py |  1 -
 ForgeTracker/forgetracker/tracker_main.py    |  4 +++-
 5 files changed, 12 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/58083948/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 9f91c6b..66d323e 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -564,7 +564,6 @@ class Message(Artifact):
     class __mongometa__:
         session = artifact_orm_session
         name='message'
-        indexes = Artifact.__mongometa__.indexes + [ 'slug', 'parent_id', 'timestamp' ]
     type_s='Generic Message'
 
     _id=FieldProperty(str, if_missing=h.gen_message_id)
@@ -594,30 +593,6 @@ class Message(Artifact):
         from .auth import User
         return User.query.get(_id=self.author_id) or User.anonymous()
 
-    def reply(self):
-        new_id = h.gen_message_id()
-        slug, full_slug = self.make_slugs(self)
-        new_args = dict(
-            state(self).document,
-            _id=new_id,
-            slug=slug,
-            full_slug=full_slug,
-            parent_id=self._id,
-            timestamp=datetime.utcnow(),
-            author_id=c.user._id)
-        return self.__class__(**new_args)
-
-    def descendants(self):
-        q = self.query.find(dict(slug={'$gt':self.slug})).sort('slug')
-        for msg in q:
-            if msg.slug.startswith(self.slug):
-                yield msg
-            else:
-                break
-
-    def replies(self):
-        return self.query.find(dict(parent_id=self._id))
-
     def index(self):
         result = Artifact.index(self)
         author = self.author()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/58083948/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 057bb97..07a6269 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -92,11 +92,15 @@ class Discussion(Artifact, ActivityObject):
 
     @LazyProperty
     def last_post(self):
+        # TODO add status: to query
         q = self.post_class().query.find(dict(
                 discussion_id=self._id))\
             .sort('timestamp', pymongo.DESCENDING)\
             .limit(1)\
-            .hint([('discussion_id', pymongo.ASCENDING), ('status', pymongo.ASCENDING)])
+            .hint([('discussion_id', pymongo.ASCENDING),
+                   ('status', pymongo.ASCENDING),
+                   ('timestamp', pymongo.ASCENDING),
+                   ])
             # hint is to try to force the index to be used, since mongo wouldn't select it
sometimes
             # https://groups.google.com/forum/#!topic/mongodb-user/0TEqPfXxQU8
         return q.first()
@@ -358,12 +362,6 @@ class Thread(Artifact, ActivityObject):
         return self.query_posts(page=page, limit=limit,
                                 timestamp=timestamp, style=style).all()
 
-    def top_level_posts(self):
-        return self.post_class().query.find(dict(
-                thread_id=self._id,
-                parent_id=None,
-                status='ok'))
-
     def url(self):
         # Can't use self.discussion because it might change during the req
         discussion = self.discussion_class().query.get(_id=self.discussion_id)
@@ -441,7 +439,10 @@ class Post(Message, VersionedArtifact, ActivityObject):
     class __mongometa__:
         name = 'post'
         history_class = PostHistory
-        indexes = [('discussion_id', 'status'), 'thread_id']
+        indexes = [
+            ('discussion_id', 'status', 'timestamp'),  # used in general lookups, last_post,
etc
+            'thread_id'
+        ]
     type_s = 'Post'
 
     thread_id = ForeignIdProperty(Thread)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/58083948/Allura/allura/tests/model/test_artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_artifact.py b/Allura/allura/tests/model/test_artifact.py
index d110d5e..639b247 100644
--- a/Allura/allura/tests/model/test_artifact.py
+++ b/Allura/allura/tests/model/test_artifact.py
@@ -158,24 +158,6 @@ def test_versioning():
     assert ss.text != pg.text
     assert pg.history().count() == 3
 
-@with_setup(setUp, tearDown)
-def test_messages():
-    m = Checkmessage()
-    assert m.author() == c.user
-    rm1 = m.reply()
-    assert rm1.slug.startswith(m.slug)
-    rm2 = rm1.reply()
-    rm3 = m.reply()
-    ThreadLocalORMSession.flush_all()
-    assert rm1 in list(m.descendants())
-    assert rm2 in list(m.descendants())
-    assert rm1 in list(m.replies())
-    assert rm2 not in list(m.replies())
-    idx = m.index()
-    assert 'author_user_name_t' in idx
-    assert 'author_display_name_t' in idx
-    assert 'timestamp_dt' in idx
-    assert m.shorthand_id() == m.slug
 
 @with_setup(setUp, tearDown)
 def test_messages_unknown_lookup():

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/58083948/Allura/allura/tests/model/test_discussion.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_discussion.py b/Allura/allura/tests/model/test_discussion.py
index 34e550a..36731bc 100644
--- a/Allura/allura/tests/model/test_discussion.py
+++ b/Allura/allura/tests/model/test_discussion.py
@@ -108,7 +108,6 @@ def test_thread_methods():
     assert t.subscription
     t.subscription = False
     assert not t.subscription
-    assert t.top_level_posts().count() == 2
     assert t.post_count == 3
     jsn = t.__json__()
     assert '_id' in jsn

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/58083948/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index 61f7a99..c273279 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -896,7 +896,9 @@ class RootController(BaseController, FeedController):
 
     def ticket_comments_since(self, when=None):
         q = dict(
-            discussion_id=c.app.config.discussion_id)
+            discussion_id=c.app.config.discussion_id,
+            status='ok',
+        )
         if when is not None:
             q['timestamp'] = {'$gte':when}
         return M.Post.query.find(q).count()


Mime
View raw message