Tighten up the uuid map code a little

This commit is contained in:
Kovid Goyal 2013-06-01 15:54:34 +05:30
parent cd85c39b39
commit dd3301c18f
2 changed files with 7 additions and 19 deletions

View File

@ -920,15 +920,13 @@ class ResultCache(SearchQueryParser): # {{{
def remove(self, id): def remove(self, id):
try: try:
uuid = self._data[id][self._uuid_column_index] self._uuid_map.pop(self._data[id][self._uuid_column_index], None)
except IndexError: except IndexError:
# id is out of bounds -- no uuid in the map to remove pass # 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:
# id is out of bounds, no point setting it to None anyway pass # id is out of bounds, no point setting it to None anyway
pass
try: try:
self._map.remove(id) self._map.remove(id)
except ValueError: except ValueError:
@ -938,12 +936,6 @@ 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]
@ -951,7 +943,7 @@ class ResultCache(SearchQueryParser): # {{{
self._uuid_map.pop(d[col], None) self._uuid_map.pop(d[col], None)
d[col] = val d[col] = val
if col == self._uuid_column_index: if col == self._uuid_column_index:
self._uuid_map[d[col]] = id self._uuid_map[val] = 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):
@ -985,7 +977,6 @@ 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 self._uuid_map[self._data[id][self._uuid_column_index]] = id
except IndexError: except IndexError:
return None return None
@ -1006,7 +997,6 @@ 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._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

View File

@ -2661,11 +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) return (self.data._uuid_map.get(uuid, None) or
if res: self.conn.get('SELECT id FROM books WHERE uuid=?', (uuid,),
return res all=False))
return self.conn.get('SELECT id FROM books WHERE uuid=?', (uuid,),
all=False)
# Convenience methods for tags_list_editor # Convenience methods for tags_list_editor
# Note: we generally do not need to refresh_ids because library_view will # Note: we generally do not need to refresh_ids because library_view will