Example #1
0
    def run(self):
        from nebula.shops.models.shop import Item
        from nebula.cache import rediscache
        from datetime import datetime
        from sqlalchemy import or_
        import re

        query = "WORLD"

        start = datetime.now()
        items = Item.query.filter(or_(
            Item.name.like('%{0}%'.format(query)),
            Item.description.like('%{0}%'.format(query))
            )).all()
        end_sql  = (datetime.now()-start).microseconds

        result = []
        items = Item.query.all()
        for item in items:
            _i = item.serialize
            _i["body"] = "{0} {1}".format(item.name, item.description)
            result.append(_i)
        rediscache.set('items', result)

        start = datetime.now()
        items = rediscache.get('items')
        result = [ item for item in items if re.match(query, item['body']) ]
        end_cache = (datetime.now()-start).microseconds

        print "SQL TOOK", end_sql, "MS"
        print "CACHE TOOK", end_cache, "MS"
        print "CACHE IS", float(end_sql)/float(end_cache), "TIMES FASTER"
Example #2
0
    def run(self):
        from nebula.shops.models.shop import Item
        from nebula.cache import rediscache

        result = []
        items = Item.query.all()
        for item in items:
            result.append(item)
        rediscache.set('items', result)