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:
Kovid Goyal 2025-07-09 08:43:51 +05:30
parent f5b3f6aa0e
commit cfd1dc75bf
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

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