mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Restoring database: Improve performance by using SQLITE savepoints when restoring individual books. Fixes #2796 (massive performance improvement for restoring database)
This commit is contained in:
parent
f5b3f6aa0e
commit
cfd1dc75bf
@ -11,7 +11,7 @@ import shutil
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
from contextlib import suppress
|
||||
from contextlib import closing, suppress
|
||||
from operator import itemgetter
|
||||
from threading import Thread
|
||||
|
||||
@ -296,7 +296,8 @@ class Restore(Thread):
|
||||
with suppress(FileNotFoundError):
|
||||
os.remove(os.path.join(notes_dest, NOTES_DB_NAME))
|
||||
db = Restorer(self.library_path)
|
||||
|
||||
with closing(db):
|
||||
with db.new_api:
|
||||
for i, book in enumerate(self.books):
|
||||
try:
|
||||
db.restore_book(book['id'], book['mi'], utcfromtimestamp(book['timestamp']), book['path'], book['formats'], book['annotations'])
|
||||
@ -306,11 +307,11 @@ class Restore(Thread):
|
||||
traceback.print_exc()
|
||||
self.progress_callback(book['mi'].title, i+1)
|
||||
|
||||
with db.new_api:
|
||||
for field, lmap in self.link_maps.items():
|
||||
with suppress(Exception):
|
||||
db.set_link_map(field, {k:v[0] for k, v in lmap.items()})
|
||||
self.notes_errors = db.backend.restore_notes(self.progress_callback)
|
||||
db.close()
|
||||
|
||||
def replace_db(self):
|
||||
dbpath = os.path.join(self.src_library_path, 'metadata.db')
|
||||
|
Loading…
x
Reference in New Issue
Block a user