From a7db68236cb051be34aaf0db2e5b2f6372dffa60 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 26 May 2014 12:11:13 +0200 Subject: [PATCH] avoid db lookups for icons --- oml/item/icons.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/oml/item/icons.py b/oml/item/icons.py index 8cdc103..7338b6e 100644 --- a/oml/item/icons.py +++ b/oml/item/icons.py @@ -91,6 +91,34 @@ icons = Icons(icons_db_path) @run_async def get_icon(app, id, type_, size, callback): + if size: + skey = '%s:%s:%s' % (type_, id, size) + data = icons[skey] + if data: + callback(str(data)) + return + key = '%s:%s' % (type_, id) + if not icons[key]: + type_ = 'preview' if type_ == 'cover' else 'cover' + if size: + skey = '%s:%s:%s' % (type_, id, size) + data = None + if size: + data = icons[skey] + if data: + size = None + if not data: + data = icons[key] + if not data: + data = icons.black() + size = None + if size: + data = icons[skey] = resize_image(data, size=size) + data = str(data) or '' + callback(data) + +@run_async +def get_icon_app(app, id, type_, size, callback): with app.app_context(): from item.models import Item item = Item.get(id)