From dd3301c18f8aa8c23c18d7cacc5fae687ec82af0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 1 Jun 2013 15:54:34 +0530 Subject: [PATCH] Tighten up the uuid map code a little --- src/calibre/library/caches.py | 18 ++++-------------- src/calibre/library/database2.py | 8 +++----- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index eb116bf00c..e552ead591 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -920,15 +920,13 @@ class ResultCache(SearchQueryParser): # {{{ def remove(self, id): try: - uuid = self._data[id][self._uuid_column_index] + self._uuid_map.pop(self._data[id][self._uuid_column_index], None) except IndexError: - # id is out of bounds -- no uuid in the map to remove - uuid = None + pass # id is out of bounds -- no uuid in the map to remove try: self._data[id] = None except IndexError: - # id is out of bounds, no point setting it to None anyway - pass + pass # id is out of bounds, no point setting it to None anyway try: self._map.remove(id) except ValueError: @@ -938,12 +936,6 @@ class ResultCache(SearchQueryParser): # {{{ except ValueError: pass - if uuid: - try: - self._uuid_map.pop(uuid, None) - except ValueError: - pass - def set(self, row, col, val, row_is_id=False): id = row if row_is_id else self._map_filtered[row] d = self._data[id] @@ -951,7 +943,7 @@ class ResultCache(SearchQueryParser): # {{{ self._uuid_map.pop(d[col], None) d[col] = val if col == self._uuid_column_index: - self._uuid_map[d[col]] = id + self._uuid_map[val] = id d.refresh_composites() 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(self.marked_ids_dict.get(id, None)) self._data[id].append(None) - self._uuid_map[self._data[id][self._uuid_column_index]] = id except IndexError: return None @@ -1006,7 +997,6 @@ class ResultCache(SearchQueryParser): # {{{ 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(None) # Series sort column - self._uuid_map[self._data[id][self._uuid_column_index]] = id self._map[0:0] = ids self._map_filtered[0:0] = ids diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 30968ff99e..98e0190ecd 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -2661,11 +2661,9 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): def get_id_from_uuid(self, 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,), - all=False) + return (self.data._uuid_map.get(uuid, None) or + self.conn.get('SELECT id FROM books WHERE uuid=?', (uuid,), + all=False)) # Convenience methods for tags_list_editor # Note: we generally do not need to refresh_ids because library_view will