mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Remove unneccessary calls to set_path when creating book records. Speeds up record creation by about 30% on my system
This commit is contained in:
parent
7ba2b0d3cf
commit
f445ccaa14
@ -1248,15 +1248,20 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
path_changed = False
|
||||||
if set_title and mi.title:
|
if set_title and mi.title:
|
||||||
self.set_title(id, mi.title, commit=False)
|
self._set_title(id, mi.title)
|
||||||
|
path_changed = True
|
||||||
if set_authors:
|
if set_authors:
|
||||||
if not mi.authors:
|
if not mi.authors:
|
||||||
mi.authors = [_('Unknown')]
|
mi.authors = [_('Unknown')]
|
||||||
authors = []
|
authors = []
|
||||||
for a in mi.authors:
|
for a in mi.authors:
|
||||||
authors += string_to_authors(a)
|
authors += string_to_authors(a)
|
||||||
self.set_authors(id, authors, notify=False, commit=False)
|
self._set_authors(id, authors)
|
||||||
|
path_changed = True
|
||||||
|
if path_changed:
|
||||||
|
self.set_path(id, index_is_id=True)
|
||||||
if mi.author_sort:
|
if mi.author_sort:
|
||||||
doit(self.set_author_sort, id, mi.author_sort, notify=False,
|
doit(self.set_author_sort, id, mi.author_sort, notify=False,
|
||||||
commit=False)
|
commit=False)
|
||||||
@ -1348,13 +1353,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
result.append(r)
|
result.append(r)
|
||||||
return ' & '.join(result).replace('|', ',')
|
return ' & '.join(result).replace('|', ',')
|
||||||
|
|
||||||
def set_authors(self, id, authors, notify=True, commit=True):
|
def _set_authors(self, id, authors):
|
||||||
'''
|
|
||||||
Note that even if commit is False, the db will still be committed to
|
|
||||||
because this causes the location of files to change
|
|
||||||
|
|
||||||
:param authors: A list of authors.
|
|
||||||
'''
|
|
||||||
if not authors:
|
if not authors:
|
||||||
authors = [_('Unknown')]
|
authors = [_('Unknown')]
|
||||||
self.conn.execute('DELETE FROM books_authors_link WHERE book=?',(id,))
|
self.conn.execute('DELETE FROM books_authors_link WHERE book=?',(id,))
|
||||||
@ -1379,25 +1378,30 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
ss = self.author_sort_from_book(id, index_is_id=True)
|
ss = self.author_sort_from_book(id, index_is_id=True)
|
||||||
self.conn.execute('UPDATE books SET author_sort=? WHERE id=?',
|
self.conn.execute('UPDATE books SET author_sort=? WHERE id=?',
|
||||||
(ss, id))
|
(ss, id))
|
||||||
self.dirtied([id], commit=False)
|
|
||||||
if commit:
|
|
||||||
self.conn.commit()
|
|
||||||
self.data.set(id, self.FIELD_MAP['authors'],
|
self.data.set(id, self.FIELD_MAP['authors'],
|
||||||
','.join([a.replace(',', '|') for a in authors]),
|
','.join([a.replace(',', '|') for a in authors]),
|
||||||
row_is_id=True)
|
row_is_id=True)
|
||||||
self.data.set(id, self.FIELD_MAP['author_sort'], ss, row_is_id=True)
|
self.data.set(id, self.FIELD_MAP['author_sort'], ss, row_is_id=True)
|
||||||
|
|
||||||
|
def set_authors(self, id, authors, notify=True, commit=True):
|
||||||
|
'''
|
||||||
|
Note that even if commit is False, the db will still be committed to
|
||||||
|
because this causes the location of files to change
|
||||||
|
|
||||||
|
:param authors: A list of authors.
|
||||||
|
'''
|
||||||
|
self._set_authors(id, authors)
|
||||||
|
self.dirtied([id], commit=False)
|
||||||
|
if commit:
|
||||||
|
self.conn.commit()
|
||||||
self.set_path(id, index_is_id=True)
|
self.set_path(id, index_is_id=True)
|
||||||
if notify:
|
if notify:
|
||||||
self.notify('metadata', [id])
|
self.notify('metadata', [id])
|
||||||
|
|
||||||
def set_title(self, id, title, notify=True, commit=True):
|
def _set_title(self, id, title):
|
||||||
'''
|
|
||||||
Note that even if commit is False, the db will still be committed to
|
|
||||||
because this causes the location of files to change
|
|
||||||
'''
|
|
||||||
if not title:
|
if not title:
|
||||||
return
|
return False
|
||||||
if not isinstance(title, unicode):
|
if isbytestring(title):
|
||||||
title = title.decode(preferred_encoding, 'replace')
|
title = title.decode(preferred_encoding, 'replace')
|
||||||
self.conn.execute('UPDATE books SET title=? WHERE id=?', (title, id))
|
self.conn.execute('UPDATE books SET title=? WHERE id=?', (title, id))
|
||||||
self.data.set(id, self.FIELD_MAP['title'], title, row_is_id=True)
|
self.data.set(id, self.FIELD_MAP['title'], title, row_is_id=True)
|
||||||
@ -1405,6 +1409,15 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
self.data.set(id, self.FIELD_MAP['sort'], title_sort(title), row_is_id=True)
|
self.data.set(id, self.FIELD_MAP['sort'], title_sort(title), row_is_id=True)
|
||||||
else:
|
else:
|
||||||
self.data.set(id, self.FIELD_MAP['sort'], title, row_is_id=True)
|
self.data.set(id, self.FIELD_MAP['sort'], title, row_is_id=True)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def set_title(self, id, title, notify=True, commit=True):
|
||||||
|
'''
|
||||||
|
Note that even if commit is False, the db will still be committed to
|
||||||
|
because this causes the location of files to change
|
||||||
|
'''
|
||||||
|
if not self._set_title(id, title):
|
||||||
|
return
|
||||||
self.set_path(id, index_is_id=True)
|
self.set_path(id, index_is_id=True)
|
||||||
self.dirtied([id], commit=False)
|
self.dirtied([id], commit=False)
|
||||||
if commit:
|
if commit:
|
||||||
@ -2072,13 +2085,12 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
(id, title, series_index, aus))
|
(id, title, series_index, aus))
|
||||||
|
|
||||||
self.data.books_added([id], self)
|
self.data.books_added([id], self)
|
||||||
self.set_path(id, True)
|
|
||||||
self.conn.commit()
|
|
||||||
if mi.timestamp is None:
|
if mi.timestamp is None:
|
||||||
mi.timestamp = utcnow()
|
mi.timestamp = utcnow()
|
||||||
if mi.pubdate is None:
|
if mi.pubdate is None:
|
||||||
mi.pubdate = utcnow()
|
mi.pubdate = utcnow()
|
||||||
self.set_metadata(id, mi, ignore_errors=True)
|
self.set_metadata(id, mi, ignore_errors=True, commit=False)
|
||||||
|
self.conn.commit()
|
||||||
if cover is not None:
|
if cover is not None:
|
||||||
try:
|
try:
|
||||||
self.set_cover(id, cover)
|
self.set_cover(id, cover)
|
||||||
@ -2114,13 +2126,12 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
id = obj.lastrowid
|
id = obj.lastrowid
|
||||||
self.data.books_added([id], self)
|
self.data.books_added([id], self)
|
||||||
ids.append(id)
|
ids.append(id)
|
||||||
self.set_path(id, True)
|
|
||||||
self.conn.commit()
|
|
||||||
if mi.timestamp is None:
|
if mi.timestamp is None:
|
||||||
mi.timestamp = utcnow()
|
mi.timestamp = utcnow()
|
||||||
if mi.pubdate is None:
|
if mi.pubdate is None:
|
||||||
mi.pubdate = utcnow()
|
mi.pubdate = utcnow()
|
||||||
self.set_metadata(id, mi)
|
self.set_metadata(id, mi, commit=False)
|
||||||
|
self.conn.commit()
|
||||||
npath = self.run_import_plugins(path, format)
|
npath = self.run_import_plugins(path, format)
|
||||||
format = os.path.splitext(npath)[-1].lower().replace('.', '').upper()
|
format = os.path.splitext(npath)[-1].lower().replace('.', '').upper()
|
||||||
stream = lopen(npath, 'rb')
|
stream = lopen(npath, 'rb')
|
||||||
@ -2154,7 +2165,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
(title, series_index, aus))
|
(title, series_index, aus))
|
||||||
id = obj.lastrowid
|
id = obj.lastrowid
|
||||||
self.data.books_added([id], self)
|
self.data.books_added([id], self)
|
||||||
self.set_path(id, True)
|
|
||||||
if mi.timestamp is None:
|
if mi.timestamp is None:
|
||||||
mi.timestamp = utcnow()
|
mi.timestamp = utcnow()
|
||||||
if mi.pubdate is None:
|
if mi.pubdate is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user