Yang Zhang committed 206350f

change get_pybook method, speed up

Comments (0)

Files changed (2)

 import base64
 import time
 from blinker import signal
-from flask.ext.cache import Cache
+#from flask.ext.cache import Cache
 pybookapp = Blueprint('pybook', __name__, static_folder='static',template_folder='templates')
 #connect db
 DATABASE = 'pybook/pybookdb'
-cache = Cache()
+cache = None
 def connect_db():
     """Returns a new connection to the database."""
 def before_request():
     """Make sure we are connected to the database each request."""
-    signal('init_cache').send(cache)
+    #signal('init_cache').send(cache)
     g.time = time.time()
     g.pybookdb = connect_db()
     # enable foreign key support
         cache.set(key, rv, timeout=60 * 60*24)
     return rv
 def get_books(limit = 15, offset = 0):
     return Pybook.get_pybook(limit, offset)


     def get_pybook(limit = 15, offset = 0):
         c = g.pybookdb.cursor()
-        c.execute("SELECT id,cover_image,title, author, subtitle, date,\
+        c.execute("SELECT id,title, author, subtitle, date,\
              publisher, number_of_page, ISBN, orginal_url FROM pybook LIMIT :limit OFFSET :offset",{'limit':limit,'offset':limit*offset})
         results = c.fetchall()
         tempbooks = []
         for result in results:
             temppyb = Pybook(result['title'], result['author'], result['subtitle'], result['date'],\
                  result['publisher'], result['number_of_page'], result['ISBN'], result['orginal_url'])
-            temppyb.cover_image = StringIO.StringIO(result['cover_image'])
    = result['id']
         return tempbooks