diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index 7a46ef3dc7..c5b3d653c3 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -190,8 +190,8 @@ class USBMS(CLI, Device): print 'in add_books_to_metadata. Prefix is None!', path, self._main_prefix continue lpath = path.partition(prefix)[2] - if lpath.startswith(os.sep): - lpath = lpath[len(os.sep):] + if lpath.startswith('/') or lpath.startswith('\\'): + lpath = lpath[1:] book = self.book_class(prefix, lpath, other=info) if book.size is None: book.size = os.stat(self.normalize_path(path)).st_size diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index c5fdbec2dd..fa77dc862f 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -1091,16 +1091,8 @@ class DeviceGUI(object): self.db_book_title_cache = {} self.db_book_uuid_cache = set() db = self.library_view.model().db - # The following is a terrible hack, made necessary because the db - # result_cache will always use the results filtered by the current - # search. We need all the db entries here. Choice was to either - # cache the search results so we can use the entire db, to duplicate - # large parts of the get_metadata code, or to use db_ids and pay the - # large performance penalty of zillions of SQL queries. Choice: - # save/restore the search state. - state = db.get_state_before_scan() - for idx in range(db.count()): - mi = db.get_metadata(idx, index_is_id=False) + for id in db.data.iterallids(): + mi = db.get_metadata(id, index_is_id=True) title = re.sub('(?u)\W|[_]', '', mi.title.lower()) if title not in self.db_book_title_cache: self.db_book_title_cache[title] = {'authors':{}, 'db_ids':{}} @@ -1109,7 +1101,6 @@ class DeviceGUI(object): self.db_book_title_cache[title]['authors'][authors] = mi self.db_book_title_cache[title]['db_ids'][mi.application_id] = mi self.db_book_uuid_cache.add(mi.uuid) - db.restore_state_after_scan(state) # Now iterate through all the books on the device, setting the # in_library field Fastest and most accurate key is the uuid. Second is diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index 45a357c1b5..e280a2178b 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -563,14 +563,6 @@ class ResultCache(SearchQueryParser): if item is not None: item[ondevice_col] = db.book_on_device_string(item[0]) - def get_state_before_scan(self): - retval = self._map_filtered - self._map_filtered = self._map - return retval - - def restore_state_after_scan(self, map_filtered): - self._map_filtered = map_filtered - def refresh(self, db, field=None, ascending=True): temp = db.conn.get('SELECT * FROM meta2') self._data = list(itertools.repeat(None, temp[-1][0]+2)) if temp else [] diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 063538656f..5971333078 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -245,8 +245,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): self.has_id = self.data.has_id self.count = self.data.count - self.get_state_before_scan = self.data.get_state_before_scan - self.restore_state_after_scan = self.data.restore_state_after_scan self.refresh_ondevice = functools.partial(self.data.refresh_ondevice, self) self.refresh()