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 = Shell(db=self.conn, stdout=buf)
|
||||||
shell.process_command('.dump')
|
shell.process_command('.dump')
|
||||||
sql = buf.getvalue()
|
sql = buf.getvalue()
|
||||||
|
del shell
|
||||||
|
del buf
|
||||||
|
|
||||||
with TemporaryFile(suffix='_tmpdb.db', dir=os.path.dirname(self.dbpath)) as tmpdb:
|
with TemporaryFile(suffix='_tmpdb.db', dir=os.path.dirname(self.dbpath)) as tmpdb:
|
||||||
callback(_('Restoring database from SQL') + '...')
|
callback(_('Restoring database from SQL') + '...')
|
||||||
@ -1008,6 +1010,9 @@ class DB(object):
|
|||||||
finally:
|
finally:
|
||||||
self.reopen()
|
self.reopen()
|
||||||
|
|
||||||
|
def vacuum(self):
|
||||||
|
self.conn.execute('VACUUM')
|
||||||
|
|
||||||
@dynamic_property
|
@dynamic_property
|
||||||
def user_version(self):
|
def user_version(self):
|
||||||
doc = 'The user version of this database'
|
doc = 'The user version of this database'
|
||||||
|
@ -1715,6 +1715,10 @@ class Cache(object):
|
|||||||
def dump_and_restore(self, callback=None, sql=None):
|
def dump_and_restore(self, callback=None, sql=None):
|
||||||
return self.backend.dump_and_restore(callback=callback, sql=sql)
|
return self.backend.dump_and_restore(callback=callback, sql=sql)
|
||||||
|
|
||||||
|
@write_api
|
||||||
|
def vacuum(self):
|
||||||
|
self.backend.vacuum()
|
||||||
|
|
||||||
@write_api
|
@write_api
|
||||||
def close(self):
|
def close(self):
|
||||||
self.backend.close()
|
self.backend.close()
|
||||||
|
@ -24,18 +24,15 @@ class DBCheck(QDialog): # {{{
|
|||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self, parent)
|
||||||
self.l = QVBoxLayout()
|
self.l = QVBoxLayout()
|
||||||
self.setLayout(self.l)
|
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...'))
|
_('This will take a while, please wait...'))
|
||||||
self.setWindowTitle(_('Checking database integrity'))
|
self.setWindowTitle(_('Vacuuming...'))
|
||||||
self.l1.setWordWrap(True)
|
self.l1.setWordWrap(True)
|
||||||
self.l.addWidget(self.l1)
|
self.l.addWidget(self.l1)
|
||||||
self.msg = QLabel('')
|
self.msg = QLabel('')
|
||||||
self.update_msg.connect(self.msg.setText, type=Qt.QueuedConnection)
|
self.update_msg.connect(self.msg.setText, type=Qt.QueuedConnection)
|
||||||
self.l.addWidget(self.msg)
|
self.l.addWidget(self.msg)
|
||||||
self.msg.setWordWrap(True)
|
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.resize(self.sizeHint() + QSize(100, 50))
|
||||||
self.error = None
|
self.error = None
|
||||||
self.db = db.new_api
|
self.db = db.new_api
|
||||||
@ -43,15 +40,15 @@ class DBCheck(QDialog): # {{{
|
|||||||
self.rejected = False
|
self.rejected = False
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
t = self.thread = Thread(target=self.dump_and_restore)
|
t = self.thread = Thread(target=self.vacuum)
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
QTimer.singleShot(100, self.check)
|
QTimer.singleShot(100, self.check)
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
|
||||||
def dump_and_restore(self):
|
def vacuum(self):
|
||||||
try:
|
try:
|
||||||
self.db.dump_and_restore(self.update_msg.emit)
|
self.db.vacuum()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
self.error = (as_unicode(e), traceback.format_exc())
|
self.error = (as_unicode(e), traceback.format_exc())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user