mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Normalized paths and performance improvements done
This commit is contained in:
parent
cd046c7898
commit
cd6c46dba5
@ -31,6 +31,8 @@ class Book(MetaInformation):
|
|||||||
MetaInformation.__init__(self, '')
|
MetaInformation.__init__(self, '')
|
||||||
|
|
||||||
self.path = os.path.join(prefix, lpath)
|
self.path = os.path.join(prefix, lpath)
|
||||||
|
if os.sep == '\\':
|
||||||
|
self.path = self.path.replace('/', '\\')
|
||||||
self.lpath = lpath
|
self.lpath = lpath
|
||||||
self.mime = mime_type_ext(path_to_ext(lpath))
|
self.mime = mime_type_ext(path_to_ext(lpath))
|
||||||
self.size = os.stat(self.path).st_size if size == None else size
|
self.size = os.stat(self.path).st_size if size == None else size
|
||||||
|
@ -10,7 +10,6 @@ driver. It is intended to be subclassed with the relevant parts implemented
|
|||||||
for a particular device.
|
for a particular device.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import posixpath
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
@ -999,44 +999,47 @@ class DeviceGUI(object):
|
|||||||
loc = [None, None, None]
|
loc = [None, None, None]
|
||||||
|
|
||||||
if reset:
|
if reset:
|
||||||
self.book_on_device_cache = None
|
self.book_db_title_cache = None
|
||||||
|
self.book_db_uuid_cache = None
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.book_on_device_cache is None:
|
if self.book_db_title_cache is None:
|
||||||
self.book_on_device_cache = []
|
self.book_db_title_cache = []
|
||||||
|
self.book_db_uuid_cache = []
|
||||||
for i, l in enumerate(self.booklists()):
|
for i, l in enumerate(self.booklists()):
|
||||||
self.book_on_device_cache.append({})
|
self.book_db_title_cache.append({})
|
||||||
|
self.book_db_uuid_cache.append(set())
|
||||||
for book in l:
|
for book in l:
|
||||||
book_title = book.title.lower() if book.title else ''
|
book_title = book.title.lower() if book.title else ''
|
||||||
book_title = re.sub('(?u)\W|[_]', '', book_title)
|
book_title = re.sub('(?u)\W|[_]', '', book_title)
|
||||||
if book_title not in self.book_on_device_cache[i]:
|
if book_title not in self.book_db_title_cache[i]:
|
||||||
self.book_on_device_cache[i][book_title] = \
|
self.book_db_title_cache[i][book_title] = \
|
||||||
{'authors':set(), 'db_ids':set(), 'uuids':set()}
|
{'authors':set(), 'db_ids':set(), 'uuids':set()}
|
||||||
book_authors = authors_to_string(book.authors).lower()
|
book_authors = authors_to_string(book.authors).lower()
|
||||||
book_authors = re.sub('(?u)\W|[_]', '', book_authors)
|
book_authors = re.sub('(?u)\W|[_]', '', book_authors)
|
||||||
self.book_on_device_cache[i][book_title]['authors'].add(book_authors)
|
self.book_db_title_cache[i][book_title]['authors'].add(book_authors)
|
||||||
id = getattr(book, 'application_id', None)
|
id = getattr(book, 'application_id', None)
|
||||||
if id is None:
|
if id is None:
|
||||||
id = book.db_id
|
id = book.db_id
|
||||||
if id is not None:
|
if id is not None:
|
||||||
self.book_on_device_cache[i][book_title]['db_ids'].add(id)
|
self.book_db_title_cache[i][book_title]['db_ids'].add(id)
|
||||||
uuid = getattr(book, 'uuid', None)
|
uuid = getattr(book, 'uuid', None)
|
||||||
if uuid is None:
|
if uuid is not None:
|
||||||
self.book_on_device_cache[i][book_title]['uuids'].add(uuid)
|
self.book_db_uuid_cache[i].add(uuid)
|
||||||
|
|
||||||
db = self.library_view.model().db
|
mi = self.library_view.model().db.get_metadata(index, index_is_id=True)
|
||||||
db_title = db.title(index, index_is_id=True).lower()
|
|
||||||
db_title = re.sub('(?u)\W|[_]', '', db_title)
|
|
||||||
db_authors = db.authors(index, index_is_id=True)
|
|
||||||
db_authors = db_authors.lower() if db_authors else ''
|
|
||||||
db_authors = re.sub('(?u)\W|[_]', '', db_authors)
|
|
||||||
db_uuid = db.uuid(index, index_is_id=True)
|
|
||||||
for i, l in enumerate(self.booklists()):
|
for i, l in enumerate(self.booklists()):
|
||||||
d = self.book_on_device_cache[i].get(db_title, None)
|
if mi.uuid in self.book_db_uuid_cache[i]:
|
||||||
if d:
|
loc[i] = True
|
||||||
if db_uuid in d['uuids'] or \
|
continue
|
||||||
index in d['db_ids'] or \
|
db_title = re.sub('(?u)\W|[_]', '', mi.title.lower())
|
||||||
db_authors in d['authors']:
|
cache = self.book_db_title_cache[i].get(db_title, None)
|
||||||
|
if cache:
|
||||||
|
if index in cache['db_ids']:
|
||||||
|
loc[i] = True
|
||||||
|
break
|
||||||
|
if mi.authors and \
|
||||||
|
re.sub('(?u)\W|[_]', '', mi.authors.lower()) in cache['authors']:
|
||||||
loc[i] = True
|
loc[i] = True
|
||||||
break
|
break
|
||||||
return loc
|
return loc
|
||||||
@ -1054,7 +1057,7 @@ class DeviceGUI(object):
|
|||||||
authors = authors_to_string(mi.authors).lower() if mi.authors else ''
|
authors = authors_to_string(mi.authors).lower() if mi.authors else ''
|
||||||
authors = re.sub('(?u)\W|[_]', '', authors)
|
authors = re.sub('(?u)\W|[_]', '', authors)
|
||||||
self.db_book_title_cache[title]['authors'].add(authors)
|
self.db_book_title_cache[title]['authors'].add(authors)
|
||||||
self.db_book_title_cache[title]['db_ids'].add(id)
|
self.db_book_title_cache[title]['db_ids'].add(mi.application_id)
|
||||||
self.db_book_uuid_cache.add(mi.uuid)
|
self.db_book_uuid_cache.add(mi.uuid)
|
||||||
|
|
||||||
# Now iterate through all the books on the device, setting the in_library field
|
# Now iterate through all the books on the device, setting the in_library field
|
||||||
@ -1065,7 +1068,7 @@ class DeviceGUI(object):
|
|||||||
for booklist in booklists:
|
for booklist in booklists:
|
||||||
for book in booklist:
|
for book in booklist:
|
||||||
if getattr(book, 'uuid', None) in self.db_book_uuid_cache:
|
if getattr(book, 'uuid', None) in self.db_book_uuid_cache:
|
||||||
self.book_in_library = True
|
book.in_library = True
|
||||||
continue
|
continue
|
||||||
|
|
||||||
book_title = book.title.lower() if book.title else ''
|
book_title = book.title.lower() if book.title else ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user