<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,5 @@
 application: onelinr
-version: 3
+version: 4
 runtime: python
 api_version: 1
 </diff>
      <filename>app.yaml</filename>
    </modified>
    <modified>
      <diff>@@ -9,12 +9,14 @@ from google.appengine.ext.webapp \
   import template
   
 from google.appengine.api import users
-
-import re  
 from google.appengine.ext.webapp.util import run_wsgi_app
 from django.conf import settings
 import textile
 
+from google.appengine.api import memcache
+
+from django.utils import simplejson
+
 settings.INSTALLED_APPS = ('django.contrib.markup', 'onelinr')
 
 SKIP_LIST = [&quot;favicon.ico&quot;,&quot;robots.txt&quot;, &quot;feed&quot;]
@@ -41,11 +43,15 @@ class Post(db.Model):
 class StartPage(webapp.RequestHandler):
 
   def get(self):
-    channels = Channel.all()
-    channels.filter(&quot;post_count &gt;&quot;, 0)
-    channels.order(&quot;-post_count&quot;)
-    channelCloud = renderChannelCloud(channels);
-    self.response.out.write(template.render('index.html', {'channels':channels,'channelCloud':channelCloud,'page_title':'Onelinr'}))
+    channelCloud = memcache.get(&quot;channelCloud&quot;)
+    if channelCloud is None:    
+      channels = Channel.all()
+      channels.filter(&quot;post_count &gt;&quot;, 0)
+      channels.order(&quot;-post_count&quot;)
+      channelCloud = renderChannelCloud(channels);
+      memcache.set(&quot;channelCloud&quot;, channelCloud, 86400)
+    
+    self.response.out.write(template.render('index.html', {'channelCloud':channelCloud,'page_title':'Onelinr'}))
 
 class ChannelPage(webapp.RequestHandler):
 
@@ -79,8 +85,8 @@ class ChannelPage(webapp.RequestHandler):
 
     channel_key = self.request.get('key')
     channel = db.get(channel_key)
+    
     q = db.GqlQuery(&quot;SELECT * FROM Post WHERE belongs_to = :channel ORDER BY post_id DESC&quot;, channel=channel)
-
     last_post = q.get()
     
     if last_post:
@@ -96,16 +102,19 @@ class ChannelPage(webapp.RequestHandler):
       handle = user.handle
     else:
       handle = &quot;&quot;
-    post = db.get(post.put())
+
+    channel.post_count += 1
     
-    # update post_count
-    if post:
-      channel = db.get(channel_key)
-      logging.info(channel.post_count)
-      channel.post_count = channel.post_count + 1
-      channel.put()
-      
-    self.response.out.write(&quot;{'post_id':&quot;+str(post.post_id)+&quot;,'text':'&quot;+re.escape(textile.textile(post.text))+&quot;', 'handle':'&quot;+re.escape(handle)+&quot;'}&quot;)
+    batch = [post, channel]
+    db.put(batch)
+    
+    d = {
+      'post_id':post.post_id,
+      'text':textile.textile(post.text),
+      'handle':handle,
+    }
+
+    self.response.out.write(simplejson.dumps(d))
 
 class HandlePage(webapp.RequestHandler):
 
@@ -162,7 +171,7 @@ class ChannelFeed(webapp.RequestHandler):
       channel.put()
     
     q = db.GqlQuery(&quot;SELECT * FROM Post WHERE belongs_to = :channel ORDER BY post_id DESC&quot;, channel=channel)   
-    posts = q.fetch(100) #100 latest is sufficient
+    posts = q.fetch(20) #20 latest is sufficient
     
     self.response.out.write(template.render('channel_feed.html', {'channel':channel, 'posts':posts}))
 
@@ -170,7 +179,7 @@ class Feed(webapp.RequestHandler):
   def get(self):
 
     q = db.GqlQuery(&quot;SELECT * FROM Post ORDER BY date_posted DESC&quot;)   
-    posts = q.fetch(100) #100 latest is sufficient
+    posts = q.fetch(20) #20 latest is sufficient
     
     self.response.out.write(template.render('feed.html', {'posts':posts}))
     
@@ -179,29 +188,34 @@ class LatestPosts(webapp.RequestHandler):
     name = url_to_channel_name(self.request.uri)
     get_from = self.request.get('from_id')
     
-    q = db.GqlQuery(&quot;SELECT * FROM Channel WHERE name = :name&quot;, name=name)
-    channel = q.get()
+    channel = memcache.get(name)
+    if channel is None:
+      q = db.GqlQuery(&quot;SELECT * FROM Channel WHERE name = :name&quot;, name=name)
+      channel = q.get()
+      memcache.set(name, channel)
     
     q = db.GqlQuery(&quot;SELECT * FROM Post WHERE belongs_to = :channel AND post_id &gt; :get_from ORDER BY post_id DESC&quot;, channel=channel, get_from=int(get_from))   
-    posts = q.fetch(100)
+    posts = q.fetch(50)
     
-    # Own JSON formatting
-    posts_json = &quot;[&quot;
-    idx = 1
+    d = {}    
     for post in posts:
       if post.posted_by:
         handle = post.posted_by.handle
       else:
         handle = &quot;&quot;
-      
-      posts_json += &quot;{'post_id':&quot;+str(post.post_id)+&quot;,'text':'&quot;+re.escape(textile.textile(post.text))+&quot;', 'handle':'&quot;+re.escape(handle)+&quot;'}&quot;
-      if idx != len(posts):
-        posts_json += &quot;,&quot;
-      idx += 1
-    posts_json += &quot;]&quot;
-        
-    self.response.out.write(posts_json)
 
+      d.update({
+        'post_id':post.post_id,
+        'text':textile.textile(post.text),
+        'handle':handle,
+      })
+    
+    if len(d) &gt; 0:  
+      tmp = [d]
+      self.response.out.write(simplejson.dumps(tmp))
+    else:
+      self.response.out.write(&quot;[]&quot;)
+      
 def main():
   application = webapp.WSGIApplication([('/', StartPage),
                                         ('/.*/handle', HandlePage),</diff>
      <filename>onelinr.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>157382d2d4d5935bed87de5e57444c52c00e0b39</id>
    </parent>
  </parents>
  <author>
    <name>Henrik Berggren</name>
    <email>hinke@hinkeb.com</email>
  </author>
  <url>http://github.com/ericw/onelinr/commit/0f6a3521f8d4f8266a0d7dbc00f13cf85d358d2b</url>
  <id>0f6a3521f8d4f8266a0d7dbc00f13cf85d358d2b</id>
  <committed-date>2008-12-11T13:13:37-08:00</committed-date>
  <authored-date>2008-12-11T13:13:37-08:00</authored-date>
  <message>Memcached channelcloud and made overall optimizations</message>
  <tree>69ea112a78ce82a2a7929169b3cb40d62d0f5bb1</tree>
  <committer>
    <name>Henrik Berggren</name>
    <email>hinke@hinkeb.com</email>
  </committer>
</commit>
