mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
newdb: Replace dump and restore with vacuum
apsw has various issues with dump and restore, so replace it with vacuum. Fixes #1217988 [Database integrity issue with V 1.0.0](https://bugs.launchpad.net/calibre/+bug/1217988)
This commit is contained in:
parent
e687b24c1f
commit
2023fb01d0
@ -995,6 +995,8 @@ class DB(object):
|
||||
shell = Shell(db=self.conn, stdout=buf)
|
||||
shell.process_command('.dump')
|
||||
sql = buf.getvalue()
|
||||
del shell
|
||||
del buf
|
||||
|
||||
with TemporaryFile(suffix='_tmpdb.db', dir=os.path.dirname(self.dbpath)) as tmpdb:
|
||||
callback(_('Restoring database from SQL') + '...')
|
||||
@ -1008,6 +1010,9 @@ class DB(object):
|
||||
finally:
|
||||
self.reopen()
|
||||
|
||||
def vacuum(self):
|
||||
self.conn.execute('VACUUM')
|
||||
|
||||
@dynamic_property
|
||||
def user_version(self):
|
||||
doc = 'The user version of this database'
|
||||
|
@ -1715,6 +1715,10 @@ class Cache(object):
|
||||
def dump_and_restore(self, callback=None, sql=None):
|
||||
return self.backend.dump_and_restore(callback=callback, sql=sql)
|
||||
|
||||
@write_api
|
||||
def vacuum(self):
|
||||
self.backend.vacuum()
|
||||
|
||||
@write_api
|
||||
def close(self):
|
||||
self.backend.close()
|
||||
|
@ -24,18 +24,15 @@ class DBCheck(QDialog): # {{{
|
||||
QDialog.__init__(self, parent)
|
||||
self.l = QVBoxLayout()
|
||||
self.setLayout(self.l)
|
||||
self.l1 = QLabel(_('Checking database integrity') + ' ' +
|
||||
self.l1 = QLabel(_('Vacuuming database to improve performance.') + ' ' +
|
||||
_('This will take a while, please wait...'))
|
||||
self.setWindowTitle(_('Checking database integrity'))
|
||||
self.setWindowTitle(_('Vacuuming...'))
|
||||
self.l1.setWordWrap(True)
|
||||
self.l.addWidget(self.l1)
|
||||
self.msg = QLabel('')
|
||||
self.update_msg.connect(self.msg.setText, type=Qt.QueuedConnection)
|
||||
self.l.addWidget(self.msg)
|
||||
self.msg.setWordWrap(True)
|
||||
self.bb = QDialogButtonBox(QDialogButtonBox.Cancel)
|
||||
self.l.addWidget(self.bb)
|
||||
self.bb.rejected.connect(self.reject)
|
||||
self.resize(self.sizeHint() + QSize(100, 50))
|
||||
self.error = None
|
||||
self.db = db.new_api
|
||||
@ -43,15 +40,15 @@ class DBCheck(QDialog): # {{{
|
||||
self.rejected = False
|
||||
|
||||
def start(self):
|
||||
t = self.thread = Thread(target=self.dump_and_restore)
|
||||
t = self.thread = Thread(target=self.vacuum)
|
||||
t.daemon = True
|
||||
t.start()
|
||||
QTimer.singleShot(100, self.check)
|
||||
self.exec_()
|
||||
|
||||
def dump_and_restore(self):
|
||||
def vacuum(self):
|
||||
try:
|
||||
self.db.dump_and_restore(self.update_msg.emit)
|
||||
self.db.vacuum()
|
||||
except Exception as e:
|
||||
import traceback
|
||||
self.error = (as_unicode(e), traceback.format_exc())
|
||||
|
Loading…
x
Reference in New Issue
Block a user