dont use like query to remove resize cache
This commit is contained in:
parent
b2f5005598
commit
609ff07214
1 changed files with 55 additions and 23 deletions
|
@ -65,31 +65,60 @@ class Icons(dict):
|
||||||
|
|
||||||
def __setitem__(self, id, data):
|
def __setitem__(self, id, data):
|
||||||
sql = 'INSERT OR REPLACE INTO icon values (?, ?)'
|
sql = 'INSERT OR REPLACE INTO icon values (?, ?)'
|
||||||
conn = self.connect()
|
try:
|
||||||
c = conn.cursor()
|
conn = self.connect()
|
||||||
data = sqlite3.Binary(data)
|
c = conn.cursor()
|
||||||
c.execute(sql, (id, data))
|
data = sqlite3.Binary(data)
|
||||||
conn.commit()
|
c.execute(sql, (id, data))
|
||||||
c.close()
|
conn.commit()
|
||||||
conn.close()
|
c.close()
|
||||||
|
conn.close()
|
||||||
|
except:
|
||||||
|
logger.debug('failed to insert icon %s', id)
|
||||||
|
|
||||||
def __delitem__(self, id):
|
def __delitem__(self, id):
|
||||||
sql = 'DELETE FROM icon WHERE id = ?'
|
sql = 'DELETE FROM icon WHERE id = ?'
|
||||||
conn = self.connect()
|
try:
|
||||||
c = conn.cursor()
|
conn = self.connect()
|
||||||
c.execute(sql, (id, ))
|
c = conn.cursor()
|
||||||
conn.commit()
|
c.execute(sql, (id, ))
|
||||||
c.close()
|
conn.commit()
|
||||||
conn.close()
|
c.close()
|
||||||
|
conn.close()
|
||||||
|
except:
|
||||||
|
logger.debug('failed to delete icon %s', id)
|
||||||
|
|
||||||
def clear(self, prefix):
|
def clear(self, prefix):
|
||||||
sql = 'DELETE FROM icon WHERE id LIKE ?'
|
try:
|
||||||
conn = self.connect()
|
conn = self.connect()
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute(sql, (prefix + '%', ))
|
sql = 'DELETE FROM icon WHERE id = ?'
|
||||||
conn.commit()
|
for size in (64, 128, 256, 512, 1024):
|
||||||
c.close()
|
id = '%s%s' % (prefix, size)
|
||||||
conn.close()
|
c.execute(sql, (id, ))
|
||||||
|
conn.commit()
|
||||||
|
c.close()
|
||||||
|
conn.close()
|
||||||
|
except:
|
||||||
|
logger.debug('failed to clear icon %s', id)
|
||||||
|
|
||||||
|
def vacuum(self, ids):
|
||||||
|
conn = self.connect()
|
||||||
|
c = conn.cursor()
|
||||||
|
sql = 'SELECT id from icon'
|
||||||
|
c.execute(sql)
|
||||||
|
icons = [row[0] for row in c]
|
||||||
|
sql = 'DELETE FROM icon WHERE id = ?'
|
||||||
|
for i in icons:
|
||||||
|
id = i.split(':')[1]
|
||||||
|
if id not in ids:
|
||||||
|
c.execute(sql, (id, ))
|
||||||
|
conn.commit()
|
||||||
|
sql = 'VACUUM'
|
||||||
|
c.execute(sql)
|
||||||
|
conn.commit()
|
||||||
|
c.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
icons = Icons(icons_db_path)
|
icons = Icons(icons_db_path)
|
||||||
|
|
||||||
|
@ -121,10 +150,12 @@ def get_icon_sync(id, type_, size):
|
||||||
if not data:
|
if not data:
|
||||||
data = icons.default_cover()
|
data = icons.default_cover()
|
||||||
if size:
|
if size:
|
||||||
data = icons[skey] = resize_image(data, size=size)
|
data = resize_image(data, size=size)
|
||||||
|
icons[skey] = data
|
||||||
size = None
|
size = None
|
||||||
if size:
|
if size:
|
||||||
data = icons[skey] = resize_image(data, size=size)
|
data = resize_image(data, size=size)
|
||||||
|
icons[skey] = data
|
||||||
data = bytes(data) or ''
|
data = bytes(data) or ''
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -161,7 +192,8 @@ def get_icon_app(id, type_, size, callback):
|
||||||
data = icons.default_cover()
|
data = icons.default_cover()
|
||||||
size = None
|
size = None
|
||||||
if size:
|
if size:
|
||||||
data = icons[skey] = resize_image(data, size=size)
|
data = resize_image(data, size=size)
|
||||||
|
icons[skey] = data
|
||||||
data = bytes(data) or ''
|
data = bytes(data) or ''
|
||||||
callback(data)
|
callback(data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue