You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2014/02/12 18:24:09 UTC

git commit: [#7164] proactively grab more activities if we have a low limit

Updated Branches:
  refs/heads/db/7164 [created] 282a1674c


[#7164] proactively grab more activities if we have a low limit

Permission filtering may cause no activities to be found unless we do this.


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

Branch: refs/heads/db/7164
Commit: 282a1674c650b6ddb6a45d718ed90d1b9387402b
Parents: 1ad33e1
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Wed Feb 12 17:23:18 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Feb 12 17:23:18 2014 +0000

----------------------------------------------------------------------
 ForgeActivity/forgeactivity/main.py             | 36 ++++++++++++++------
 .../forgeactivity/tests/functional/test_root.py |  7 +---
 2 files changed, 26 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/282a1674/ForgeActivity/forgeactivity/main.py
----------------------------------------------------------------------
diff --git a/ForgeActivity/forgeactivity/main.py b/ForgeActivity/forgeactivity/main.py
index 4df5dbe..f95d7c0 100644
--- a/ForgeActivity/forgeactivity/main.py
+++ b/ForgeActivity/forgeactivity/main.py
@@ -17,6 +17,7 @@
 
 import logging
 import calendar
+from itertools import islice, ifilter
 
 from pylons import tmpl_context as c, app_globals as g
 from pylons import request, response
@@ -99,19 +100,29 @@ class ForgeActivityController(BaseController):
             actor_only = False
 
         following = g.director.is_connected(c.user, followee)
-        timeline = g.director.get_timeline(followee, page=kw.get('page', 0),
-                                           limit=kw.get('limit', 100),
-                                           actor_only=actor_only,
-                                           filter_func=perm_check(c.user))
         page = asint(kw.get('page', 0))
-        limit = asint(kw.get('limit', 100))
+        limit = extra_limit = asint(kw.get('limit', 100))
+        # get more in case perm check filters some out
+        if page == 0 and limit <= 10:
+            extra_limit = limit * 20
+        timeline = g.director.get_timeline(followee, page,
+                                           limit=extra_limit,
+                                           actor_only=actor_only)
+        filtered_timeline = list(islice(ifilter(perm_check(c.user), timeline),
+                                        0, limit))
+        if extra_limit == limit:
+            # if we didn't ask for extra, then we expect there's more if we got all we asked for
+            has_more = len(timeline) == limit
+        else:
+            # if we did ask for extra, check filtered result
+            has_more = len(filtered_timeline) == limit
         return dict(
             followee=followee,
             following=following,
-            timeline=timeline,
+            timeline=filtered_timeline,
             page=page,
             limit=limit,
-            has_more=len(timeline) == limit)
+            has_more=has_more)
 
     @expose('jinja:forgeactivity:templates/index.html')
     @with_trailing_slash
@@ -227,14 +238,17 @@ class ForgeActivityProfileSection(ProfileSectionBase):
         return app_installed and activity_enabled
 
     def prepare_context(self, context):
+        full_timeline = g.director.get_timeline(
+            self.user, page=0, limit=100,
+            actor_only=True,
+        )
+        filtered_timeline = list(islice(ifilter(perm_check(c.user), full_timeline),
+                                        0, 5))
         context.update({
             'user': self.user,
             'follow_toggle': W.follow_toggle,
             'following': g.director.is_connected(c.user, self.user),
-            'timeline': g.director.get_timeline(
-                self.user, page=0, limit=5,
-                actor_only=True,
-                filter_func=perm_check(c.user)),
+            'timeline': filtered_timeline,
             'activity_app': self.activity_app,
         })
         g.register_js('activity_js/follow.js')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/282a1674/ForgeActivity/forgeactivity/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeActivity/forgeactivity/tests/functional/test_root.py b/ForgeActivity/forgeactivity/tests/functional/test_root.py
index 2074866..197825a 100644
--- a/ForgeActivity/forgeactivity/tests/functional/test_root.py
+++ b/ForgeActivity/forgeactivity/tests/functional/test_root.py
@@ -41,7 +41,7 @@ class TestActivityController(TestController):
 
     def test_index(self):
         resp = self.app.get('/activity/')
-        assert 'No activity to display.' in resp
+        assert 'No activity to display.' in resp, resp
 
     def test_index_disabled(self):
         config['activitystream.enabled'] = 'false'
@@ -56,7 +56,6 @@ class TestActivityController(TestController):
             "_id": ObjectId("529fa331033c5e6406d8b338"),
             "obj": {
                 "activity_extras": {
-                    "allura_id": "some_id",
                     "summary": "Just wanted to leave a comment on this..."
                 },
                 "activity_url": "/p/test/tickets/34/?limit=25#ed7c",
@@ -177,7 +176,6 @@ class TestActivityController(TestController):
             "_id": ObjectId("529fa331033c5e6406d8b338"),
             "obj": {
                 "activity_extras": {
-                    "allura_id": "some_id",
                     "summary": "Just wanted to leave a comment on this..."
                 },
                 "activity_url": "/p/test/tickets/34/?limit=25#ed7c",
@@ -229,7 +227,6 @@ class TestActivityController(TestController):
             "_id": ObjectId("529fa331033c5e6406d8b338"),
             "obj": {
                 "activity_extras": {
-                    "allura_id": "some_id",
                     "summary": "Just wanted to leave a comment on this..."
                 },
                 "activity_url": "/p/test/tickets/34/?limit=25#ed7c",
@@ -280,7 +277,6 @@ class TestActivityController(TestController):
             "_id": ObjectId("529fa331033c5e6406d8b338"),
             "obj": {
                 "activity_extras": {
-                    "allura_id": "some_id",
                     "summary": "Just wanted to leave a comment on this..."
                 },
                 "activity_url": "/p/test/tickets/34/?limit=25#ed7c",
@@ -337,7 +333,6 @@ class TestActivityController(TestController):
             "_id": ObjectId("529fa331033c5e6406d8b338"),
             "obj": {
                 "activity_extras": {
-                    "allura_id": "some_id",
                     "summary": "Just wanted to leave a comment on this..."
                 },
                 "activity_url": "/p/test/tickets/34/?limit=25#ed7c",