mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
Speed up retrieving books by uuid by keeping an in memory uuid->id cache.
This commit is contained in:
commit
cd85c39b39
@ -221,6 +221,8 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
# Do this here so the var get updated when a library changes
|
# Do this here so the var get updated when a library changes
|
||||||
global pref_use_primary_find_in_search
|
global pref_use_primary_find_in_search
|
||||||
pref_use_primary_find_in_search = prefs['use_primary_find_in_search']
|
pref_use_primary_find_in_search = prefs['use_primary_find_in_search']
|
||||||
|
self._uuid_column_index = self.FIELD_MAP['uuid']
|
||||||
|
self._uuid_map = {}
|
||||||
|
|
||||||
def break_cycles(self):
|
def break_cycles(self):
|
||||||
self._data = self.field_metadata = self.FIELD_MAP = \
|
self._data = self.field_metadata = self.FIELD_MAP = \
|
||||||
@ -917,6 +919,11 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def remove(self, id):
|
def remove(self, id):
|
||||||
|
try:
|
||||||
|
uuid = self._data[id][self._uuid_column_index]
|
||||||
|
except IndexError:
|
||||||
|
# id is out of bounds -- no uuid in the map to remove
|
||||||
|
uuid = None
|
||||||
try:
|
try:
|
||||||
self._data[id] = None
|
self._data[id] = None
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@ -931,10 +938,20 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if uuid:
|
||||||
|
try:
|
||||||
|
self._uuid_map.pop(uuid, None)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
def set(self, row, col, val, row_is_id=False):
|
def set(self, row, col, val, row_is_id=False):
|
||||||
id = row if row_is_id else self._map_filtered[row]
|
id = row if row_is_id else self._map_filtered[row]
|
||||||
d = self._data[id]
|
d = self._data[id]
|
||||||
|
if col == self._uuid_column_index:
|
||||||
|
self._uuid_map.pop(d[col], None)
|
||||||
d[col] = val
|
d[col] = val
|
||||||
|
if col == self._uuid_column_index:
|
||||||
|
self._uuid_map[d[col]] = id
|
||||||
d.refresh_composites()
|
d.refresh_composites()
|
||||||
|
|
||||||
def get(self, row, col, row_is_id=False):
|
def get(self, row, col, row_is_id=False):
|
||||||
@ -968,6 +985,8 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
self._data[id].append(db.book_on_device_string(id))
|
self._data[id].append(db.book_on_device_string(id))
|
||||||
self._data[id].append(self.marked_ids_dict.get(id, None))
|
self._data[id].append(self.marked_ids_dict.get(id, None))
|
||||||
self._data[id].append(None)
|
self._data[id].append(None)
|
||||||
|
|
||||||
|
self._uuid_map[self._data[id][self._uuid_column_index]] = id
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
@ -987,6 +1006,8 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
self._data[id].append(db.book_on_device_string(id))
|
self._data[id].append(db.book_on_device_string(id))
|
||||||
self._data[id].append(self.marked_ids_dict.get(id, None))
|
self._data[id].append(self.marked_ids_dict.get(id, None))
|
||||||
self._data[id].append(None) # Series sort column
|
self._data[id].append(None) # Series sort column
|
||||||
|
|
||||||
|
self._uuid_map[self._data[id][self._uuid_column_index]] = id
|
||||||
self._map[0:0] = ids
|
self._map[0:0] = ids
|
||||||
self._map_filtered[0:0] = ids
|
self._map_filtered[0:0] = ids
|
||||||
|
|
||||||
@ -1013,6 +1034,8 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
for r in temp:
|
for r in temp:
|
||||||
self._data[r[0]] = CacheRow(db, self.composites, r,
|
self._data[r[0]] = CacheRow(db, self.composites, r,
|
||||||
self.series_col, self.series_sort_col)
|
self.series_col, self.series_sort_col)
|
||||||
|
self._uuid_map[self._data[r[0]][self._uuid_column_index]] = r[0]
|
||||||
|
|
||||||
for item in self._data:
|
for item in self._data:
|
||||||
if item is not None:
|
if item is not None:
|
||||||
item.append(db.book_on_device_string(item[0]))
|
item.append(db.book_on_device_string(item[0]))
|
||||||
|
@ -2661,6 +2661,9 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
|
|
||||||
def get_id_from_uuid(self, uuid):
|
def get_id_from_uuid(self, uuid):
|
||||||
if uuid:
|
if uuid:
|
||||||
|
res = self.data._uuid_map.get(uuid, None)
|
||||||
|
if res:
|
||||||
|
return res
|
||||||
return self.conn.get('SELECT id FROM books WHERE uuid=?', (uuid,),
|
return self.conn.get('SELECT id FROM books WHERE uuid=?', (uuid,),
|
||||||
all=False)
|
all=False)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user