Skip to content

Commit

Permalink
cache fix
Browse files Browse the repository at this point in the history
  • Loading branch information
systempuntoout committed Dec 6, 2011
1 parent 357f7f3 commit 5fca893
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 27 deletions.
30 changes: 24 additions & 6 deletions app/config/settings.py
Expand Up @@ -7,7 +7,7 @@
*App Engine knowledge base directory*"""
META_DESCRIPTION = u"GAE Cupboard - Ingredients for your Google App Engine recipes"
META_KEYWORDS = u"Gae appengine Google App Engine libraries tutorial videos projects stackoverflow "
CATEGORIES = [u"Libraries",u"Articles",u"Books", u"Questions", u"Videos", u"Applications"]
CATEGORIES = [u"Libraries",u"Articles",u"Books", u"Questions", u"Videos", u"Applications", u"Jobs"]
MAIL_ADMIN = u"systempuntoout@gmail.com"
HOST = "www.gaecupboard.com" #Insert your host here: foo.appspot.com or in case of custom domain www.foo.com
REDIRECT_FROM_APPENGINE_HOST_TO_HOST = True
Expand All @@ -21,15 +21,24 @@
Do you want some good tags/categories combo to start with?
Try with:
- [web-frameworks+python](http://www.gaecupboard.com/tag/web-frameworks/python?category=Libraries) in the _Libraries_ category
- [reviews](http://www.gaecupboard.com/tag/reviews?category=Articles) in the _Articles_ category
- [rants](http://www.gaecupboard.com/tag/rants?category=Articles) in the _Articles_ category
- [java](http://www.gaecupboard.com/tag/java?category=Books) in the _Books_ category
- [pricing](http://www.gaecupboard.com/tag/pricing?category=Articles) in the _Articles_ category
- [web-frameworks+python](http://www.gaecupboard.com/tag/web-frameworks/python?category=Libraries) in the _Libraries_ category
- [reviews](http://www.gaecupboard.com/tag/reviews?category=Articles) in the _Articles_ category
- [rants](http://www.gaecupboard.com/tag/rants?category=Articles) in the _Articles_ category
- [java](http://www.gaecupboard.com/tag/java?category=Books) in the _Books_ category
- [pricing](http://www.gaecupboard.com/tag/pricing?category=Articles) in the _Articles_ category
You can find me on Stack Overflow as [Systempuntoout](http://stackoverflow.com/search?q=user%3A130929+%5Bgoogle-app-engine%5D), on [twitter](https://twitter.com/#!/systempuntoout) or at the following mail address:
![test](/images/systempuntooutmail.jpg "mail")
Sponsors:
-[Link slot #1](#)
-[Link slot #2](#)
-[Link slot #3](#)
-[Link slot #4](#)
-[Link slot #5](#)
"""

FOOTER = " | ".join([u"© "+ AUTHOR_NAME, CMS_NAME,"Powered by Google App Engine"])
Expand Down Expand Up @@ -178,6 +187,15 @@
"scrolling="no"marginwidth="0"marginheight="0"frameborder="0">
</iframe>"""
},
'https://www.odesk.com':{
'image':'odesk.png',
'category':'Jobs',
},
'http://careers.stackoverflow.com':{
'image':'careers.png',
'category':'Jobs',
},

}

AUTO_CONTENT_BY_CATEGORY = {
Expand Down
44 changes: 23 additions & 21 deletions app/db/models.py
Expand Up @@ -60,30 +60,32 @@ def get_posts_count(tags_filter = [], category_filter = ''):
return posts.count(limit = None)

@staticmethod
@memcached('get_posts', 3600*24, lambda page, limit, offset, tags_filter = [], category_filter = '': "%s_%s_%s_%s" % (limit,offset,'.'.join(sorted(tags_filter)), category_filter))
def get_posts(page, limit, offset, tags_filter = [], category_filter = ''):
posts = Post.all()
if category_filter:
posts.filter('category', category_filter )
for tag in tags_filter:
if tag:
posts.filter('tags', tag)
bookmark = memcache.get("%s:%s_%s_%s" % ('get_posts_cursor', page-1,'.'.join(sorted(tags_filter)), category_filter))
if bookmark:
posts.with_cursor(start_cursor = bookmark)
fetched_post = posts.fetch(limit = limit)
memcache.set("%s:%s_%s_%s" % ('get_posts_cursor', page,'.'.join(sorted(tags_filter)), category_filter), posts.cursor())
else:
if offset == 0:
fetched_post = posts.fetch(limit = limit)
fetched_posts = memcache.get("%s:%s_%s_%s_%s" % ('get_posts',limit,page,'.'.join(sorted(tags_filter)), category_filter))
bookmark = memcache.get("%s:%s_%s_%s" % ('get_posts_cursor', page,'.'.join(sorted(tags_filter)), category_filter))
if not fetched_posts or not bookmark:
posts = Post.all()
if category_filter:
posts.filter('category', category_filter )
for tag in tags_filter:
if tag:
posts.filter('tags', tag)
bookmark = memcache.get("%s:%s_%s_%s" % ('get_posts_cursor', page-1,'.'.join(sorted(tags_filter)), category_filter))
if bookmark:
posts.with_cursor(start_cursor = bookmark)
fetched_posts = posts.fetch(limit = limit)
memcache.set("%s:%s_%s_%s" % ('get_posts_cursor', page,'.'.join(sorted(tags_filter)), category_filter), posts.cursor())
else:
memcache.delete('get_posts:%s_%s_%s_%s' % (limit,POSTS_PER_PAGE - offset,'.'.join(sorted(tags_filter)), category_filter))
#Offset consumes a lot of Datastore reads, without bookmark I return nothing
fetched_post = []


return fetched_post
if page == 1:
fetched_posts = posts.fetch(limit = limit)
memcache.set("%s:%s_%s_%s" % ('get_posts_cursor', page,'.'.join(sorted(tags_filter)), category_filter), posts.cursor())
else:
#Offset consumes a lot of Datastore reads, without bookmark you get nothing
fetched_posts = []
if fetched_posts:
memcache.set("%s:%s_%s_%s_%s" % ('get_posts',limit,page,'.'.join(sorted(tags_filter)), category_filter), fetched_posts)
return fetched_posts

@staticmethod
@memcached('get_recent_posts', 3600*24)
Expand Down
Binary file added app/static/images/predefined/careers.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/images/predefined/jobs.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/images/predefined/odesk.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/views/__init__.py
Expand Up @@ -630,6 +630,9 @@ def post (post, prev_post = None, next_post = None, content_discovered = '', is_
if settings.DISQUS and not development:
extend_([' ', u'<h3 id="comments">Comments</h3>\n'])
extend_([' ', u'<div id="disqus_thread"></div>\n'])
extend_([' ', u'<script type="text/javascript">\n'])
extend_([' ', u" var disqus_identifier = '", escape_(post.key(), True), u"';\n"])
extend_([' ', u'</script>\n'])
if development:
extend_([' ', u'<script type="text/javascript">\n'])
extend_([' ', u' var disqus_developer = 1;\n'])
Expand Down
3 changes: 3 additions & 0 deletions app/views/post.html
Expand Up @@ -66,6 +66,9 @@
$if settings.DISQUS and not development:
<h3 id="comments">Comments</h3>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_identifier = '$post.key()';
</script>
$if development:
<script type="text/javascript">
var disqus_developer = 1;
Expand Down

0 comments on commit 5fca893

Please sign in to comment.