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):
|
||||
sql = 'INSERT OR REPLACE INTO icon values (?, ?)'
|
||||
conn = self.connect()
|
||||
c = conn.cursor()
|
||||
data = sqlite3.Binary(data)
|
||||
c.execute(sql, (id, data))
|
||||
conn.commit()
|
||||
c.close()
|
||||
conn.close()
|
||||
try:
|
||||
conn = self.connect()
|
||||
c = conn.cursor()
|
||||
data = sqlite3.Binary(data)
|
||||
c.execute(sql, (id, data))
|
||||
conn.commit()
|
||||
c.close()
|
||||
conn.close()
|
||||
except:
|
||||
logger.debug('failed to insert icon %s', id)
|
||||
|
||||
def __delitem__(self, id):
|
||||
sql = 'DELETE FROM icon WHERE id = ?'
|
||||
conn = self.connect()
|
||||
c = conn.cursor()
|
||||
c.execute(sql, (id, ))
|
||||
conn.commit()
|
||||
c.close()
|
||||
conn.close()
|
||||
try:
|
||||
conn = self.connect()
|
||||
c = conn.cursor()
|
||||
c.execute(sql, (id, ))
|
||||
conn.commit()
|
||||
c.close()
|
||||
conn.close()
|
||||
except:
|
||||
logger.debug('failed to delete icon %s', id)
|
||||
|
||||
def clear(self, prefix):
|
||||
sql = 'DELETE FROM icon WHERE id LIKE ?'
|
||||
conn = self.connect()
|
||||
c = conn.cursor()
|
||||
c.execute(sql, (prefix + '%', ))
|
||||
conn.commit()
|
||||
c.close()
|
||||
conn.close()
|
||||
try:
|
||||
conn = self.connect()
|
||||
c = conn.cursor()
|
||||
sql = 'DELETE FROM icon WHERE id = ?'
|
||||
for size in (64, 128, 256, 512, 1024):
|
||||
id = '%s%s' % (prefix, size)
|
||||
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)
|
||||
|
||||
|
@ -121,10 +150,12 @@ def get_icon_sync(id, type_, size):
|
|||
if not data:
|
||||
data = icons.default_cover()
|
||||
if size:
|
||||
data = icons[skey] = resize_image(data, size=size)
|
||||
data = resize_image(data, size=size)
|
||||
icons[skey] = data
|
||||
size = None
|
||||
if size:
|
||||
data = icons[skey] = resize_image(data, size=size)
|
||||
data = resize_image(data, size=size)
|
||||
icons[skey] = data
|
||||
data = bytes(data) or ''
|
||||
return data
|
||||
|
||||
|
@ -161,7 +192,8 @@ def get_icon_app(id, type_, size, callback):
|
|||
data = icons.default_cover()
|
||||
size = None
|
||||
if size:
|
||||
data = icons[skey] = resize_image(data, size=size)
|
||||
data = resize_image(data, size=size)
|
||||
icons[skey] = data
|
||||
data = bytes(data) or ''
|
||||
callback(data)
|
||||
|
||||
|
|
Loading…
Reference in a new issue