launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #15618
[Merge] lp:~stevenk/launchpad/memcache-getRecentBlogPosts into lp:launchpad
Steve Kowalik has proposed merging lp:~stevenk/launchpad/memcache-getRecentBlogPosts into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~stevenk/launchpad/memcache-getRecentBlogPosts/+merge/165281
Cache the latest blog posts using memcache. If it's in the cache, we pull it out and return it, and if it isn't we do the usual thing and store it in memcache before returning it.
--
https://code.launchpad.net/~stevenk/launchpad/memcache-getRecentBlogPosts/+merge/165281
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/memcache-getRecentBlogPosts into lp:launchpad.
=== modified file 'lib/lp/app/browser/root.py'
--- lib/lp/app/browser/root.py 2013-04-10 07:45:16 +0000
+++ lib/lp/app/browser/root.py 2013-05-23 04:12:29 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Browser code for the Launchpad root page."""
@@ -44,6 +44,7 @@
GoogleResponseError,
ISearchService,
)
+from lp.services.memcache.interfaces import IMemcacheClient
from lp.services.propertycache import cachedproperty
from lp.services.statistics.interfaces.statistic import ILaunchpadStatisticSet
from lp.services.timeout import urlfetch
@@ -157,13 +158,14 @@
launchpad.homepage_recent_posts_count. The posts are fetched
from the feed specified in launchpad.homepage_recent_posts_feed.
- Since the feed is parsed everytime, the template should cache this
- through memcached.
-
FeedParser takes care of sanitizing the HTML contained in the feed.
"""
- # Use urlfetch which supports timeout
+ key = '%s:cached-blog-entries' % config.instance_name
+ cached_data = getUtility(IMemcacheClient).get(key)
+ if cached_data:
+ return cached_data
try:
+ # Use urlfetch which supports timeout
data = urlfetch(config.launchpad.homepage_recent_posts_feed)
except IOError:
return []
@@ -178,6 +180,7 @@
'link': entry.link,
'date': time.strftime('%d %b %Y', entry.updated_parsed),
})
+ getUtility(IMemcacheClient).set(key, posts)
return posts
=== modified file 'lib/lp/app/browser/tests/test_launchpadroot.py'
--- lib/lp/app/browser/tests/test_launchpadroot.py 2012-08-13 17:40:23 +0000
+++ lib/lp/app/browser/tests/test_launchpadroot.py 2013-05-23 04:12:29 +0000
@@ -1,4 +1,4 @@
-# Copyright 2010 Canonical Ltd. This software is licensed under the
+# Copyright 2010-2013 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests related to ILaunchpadRoot."""
@@ -16,7 +16,9 @@
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
from lp.registry.interfaces.person import IPersonSet
+from lp.services.config import config
from lp.services.features.testing import FeatureFixture
+from lp.services.memcache.interfaces import IMemcacheClient
from lp.services.webapp.authorization import check_permission
from lp.services.webapp.interfaces import ILaunchpadRoot
from lp.testing import (
@@ -24,7 +26,10 @@
login_person,
TestCaseWithFactory,
)
-from lp.testing.layers import DatabaseFunctionalLayer
+from lp.testing.layers import (
+ DatabaseFunctionalLayer,
+ LaunchpadFunctionalLayer,
+ )
from lp.testing.publication import test_traverse
from lp.testing.views import (
create_initialized_view,
@@ -118,7 +123,7 @@
class LaunchpadRootIndexViewTestCase(TestCaseWithFactory):
- layer = DatabaseFunctionalLayer
+ layer = LaunchpadFunctionalLayer
def setUp(self):
super(LaunchpadRootIndexViewTestCase, self).setUp()
@@ -202,3 +207,21 @@
# column rather than blank space when the blog is not being displayed.
self.assertTrue(view.show_whatslaunchpad)
self.assertTrue(markup.find(True, 'homepage-whatslaunchpad'))
+
+ def test_blog_posts_with_memcache(self):
+ self.useFixture(FeatureFixture({'app.root_blog.enabled': True}))
+ posts = [
+ self._make_blog_post(1, "A post", "Post contents.", "2002"),
+ self._make_blog_post(2, "Another post", "More contents.", "2003"),
+ ]
+ key = '%s:cached-blog-entries' % config.instance_name
+ getUtility(IMemcacheClient).set(key, posts)
+
+ root = getUtility(ILaunchpadRoot)
+ with anonymous_logged_in() as user:
+ view = create_initialized_view(root, 'index.html', principle=user)
+ result = view()
+ markup = BeautifulSoup(result,
+ parseOnlyThese=SoupStrainer(id='homepage-blogposts'))
+ items = markup.findAll('li', 'news')
+ self.assertEqual(3, len(items))
Follow ups