1) changes to ondevice scan to use Kovid's iterator

2) correction to path construction in USMBS
This commit is contained in:
Charles Haley 2010-05-16 18:56:56 +01:00
parent d29cfd266f
commit 1e90881b90
4 changed files with 4 additions and 23 deletions

View File

@ -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

View File

@ -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

View File

@ -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 []

View File

@ -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()