google-code-export / gaewiki

Automatically exported from code.google.com/p/gaewiki
1 stars 0 forks source link

more performance using memcache #55

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
diff -urN -x '*.yaml' -x '*.bat' -x '*.pyc' gaewiki.orig/gaewiki/__init__.py 
gaewiki/gaewiki/__init__.py
--- gaewiki.orig/gaewiki/__init__.py    2011-05-01 04:45:34 +0900
+++ gaewiki/gaewiki/__init__.py 2011-11-30 23:40:21 +0900
@@ -13,7 +13,12 @@

 import handlers

-if __name__ == '__main__':
+application = None
+
+def main():
+    wsgiref.handlers.CGIHandler().run(application)
+
+if __name__ == "__main__":
     debug = os.environ['SERVER_SOFTWARE'].startswith('Development/')
     if debug:
         logging.getLogger().setLevel(logging.DEBUG)
@@ -21,4 +26,5 @@
     sys.path.insert(0, os.path.dirname(__file__))
     template.register_template_library('filters')

-    
wsgiref.handlers.CGIHandler().run(webapp.WSGIApplication(handlers.handlers, 
debug=debug))
+    application = webapp.WSGIApplication(handlers.handlers, debug=debug)
+    main()
diff -urN -x '*.yaml' -x '*.bat' -x '*.pyc' gaewiki.orig/gaewiki/model.py 
gaewiki/gaewiki/model.py
--- gaewiki.orig/gaewiki/model.py   2011-08-05 01:20:06 +0900
+++ gaewiki/gaewiki/model.py    2011-11-30 23:21:50 +0900
@@ -7,6 +7,7 @@

 from google.appengine.api import users
 from google.appengine.ext import db
+from google.appengine.api import memcache

 import settings
 import util
@@ -221,6 +222,7 @@
         # TODO: cross-link

         self.put()
+        memcache.delete(self.title)

     def get_history(self):
         return WikiRevision.gql('WHERE title = :1 ORDER BY created DESC', self.title).fetch(100)
@@ -262,11 +264,15 @@
         """Finds and loads the page by its title, creates a new one if nothing
         could be found."""
         title = title.replace('_', ' ')
-        page = cls.gql('WHERE title = :1', title).get()
+        page = memcache.get(title)
+        if page is None:
+            page = cls.gql('WHERE title = :1', title).get()
         if page is None:
             page = cls(title=title)
             if default_body is not None:
                 page.body = default_body
+        else:
+            memcache.set(title, page)
         return page

     @classmethod

Original issue reported on code.google.com by h.rayflood on 30 Nov 2011 at 2:51

GoogleCodeExporter commented 9 years ago
I misstook memcache key 'gaewiki:settings'
It conflicts at settings.py:36

diff -urN -x '*.yaml' -x '*.bat' -x '*.pyc' gaewiki.orig/gaewiki/model.py 
gaewiki/gaewiki/model.py
--- gaewiki.orig/gaewiki/model.py   2011-08-05 01:20:06 +0900
+++ gaewiki/gaewiki/model.py    2011-12-01 00:24:50 +0900
@@ -262,11 +264,18 @@
         """Finds and loads the page by its title, creates a new one if nothing
         could be found."""
         title = title.replace('_', ' ')
-        page = cls.gql('WHERE title = :1', title).get()
+
+        page = None
+        if title != 'gaewiki:settings':
+            page = memcache.get(title)
+        if page is None:
+            page = cls.gql('WHERE title = :1', title).get()
         if page is None:
             page = cls(title=title)
             if default_body is not None:
                 page.body = default_body
+        elif title != 'gaewiki:settings':
+            memcache.set(title, page)
         return page

     @classmethod

Original comment by h.rayflood on 30 Nov 2011 at 3:34

GoogleCodeExporter commented 9 years ago

Original comment by justin.forest on 30 Nov 2011 at 3:47

GoogleCodeExporter commented 9 years ago
I moved memcache.delete(self.title) from update() to put().

diff -urN -x '*.yaml' -x '*.bat' -x '*.pyc' gaewiki.orig/gaewiki/model.py 
gaewiki/gaewiki/model.py
--- gaewiki.orig/gaewiki/model.py   2011-08-05 01:20:06 +0900
+++ gaewiki/gaewiki/model.py    2011-12-01 01:15:51 +0900
@@ -173,6 +174,7 @@
         self.add_implicit_labels()
         db.Model.put(self)
         settings.check_and_flush(self)
+        memcache.delete(self.title)

     def __update_geopt(self):
         """Updates the geopt property from the appropriate page property.

Original comment by h.rayflood on 30 Nov 2011 at 4:21

GoogleCodeExporter commented 9 years ago
This issue was updated by revision cd230a64825b.

Use the main() function.

Original comment by justin.forest on 30 Nov 2011 at 7:27

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 5780787267c5.

Original comment by justin.forest on 30 Nov 2011 at 7:27

GoogleCodeExporter commented 9 years ago
Thank you.

Original comment by justin.forest on 30 Nov 2011 at 7:33