mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Implement vacuuming for notes db
This commit is contained in:
parent
bdcd3b6203
commit
713f1af61e
@ -1384,10 +1384,12 @@ class DB:
|
|||||||
finally:
|
finally:
|
||||||
self.reopen()
|
self.reopen()
|
||||||
|
|
||||||
def vacuum(self, include_fts_db):
|
def vacuum(self, include_fts_db, include_notes_db):
|
||||||
self.execute('VACUUM')
|
self.execute('VACUUM')
|
||||||
if self.fts_enabled and include_fts_db:
|
if self.fts_enabled and include_fts_db:
|
||||||
self.fts.vacuum()
|
self.fts.vacuum()
|
||||||
|
if include_notes_db:
|
||||||
|
self.notes.vacuum()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def user_version(self):
|
def user_version(self):
|
||||||
|
@ -2690,10 +2690,10 @@ class Cache:
|
|||||||
return self.backend.dump_and_restore(callback=callback, sql=sql)
|
return self.backend.dump_and_restore(callback=callback, sql=sql)
|
||||||
|
|
||||||
@write_api
|
@write_api
|
||||||
def vacuum(self, include_fts_db=False):
|
def vacuum(self, include_fts_db=False, include_notes_db=True):
|
||||||
self.is_doing_rebuild_or_vacuum = True
|
self.is_doing_rebuild_or_vacuum = True
|
||||||
try:
|
try:
|
||||||
self.backend.vacuum(include_fts_db)
|
self.backend.vacuum(include_fts_db, include_notes_db)
|
||||||
finally:
|
finally:
|
||||||
self.is_doing_rebuild_or_vacuum = False
|
self.is_doing_rebuild_or_vacuum = False
|
||||||
|
|
||||||
|
@ -369,3 +369,6 @@ class Notes:
|
|||||||
shutil.copyfileobj(src, dest)
|
shutil.copyfileobj(src, dest)
|
||||||
add_dir(self.backup_dir)
|
add_dir(self.backup_dir)
|
||||||
add_dir(self.resources_dir)
|
add_dir(self.resources_dir)
|
||||||
|
|
||||||
|
def vacuum(self, conn):
|
||||||
|
conn.execute('VACUUM notes_db')
|
||||||
|
@ -52,6 +52,15 @@ class DBCheck(QDialog): # {{{
|
|||||||
' depending on the size of the Full text database.'))
|
' depending on the size of the Full text database.'))
|
||||||
la.setWordWrap(True)
|
la.setWordWrap(True)
|
||||||
l.addWidget(la)
|
l.addWidget(la)
|
||||||
|
|
||||||
|
self.notes = n = QCheckBox(_('Also compact the notes database'))
|
||||||
|
l.addWidget(n)
|
||||||
|
la = QLabel('<p style="margin-left: 20px; font-style: italic">' + _(
|
||||||
|
'This can be a very slow and memory intensive operation,'
|
||||||
|
' depending on the size of the notes database.'))
|
||||||
|
la.setWordWrap(True)
|
||||||
|
l.addWidget(la)
|
||||||
|
|
||||||
l.addStretch(10)
|
l.addStretch(10)
|
||||||
self.bb1 = bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel, self)
|
self.bb1 = bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel, self)
|
||||||
l.addWidget(bb)
|
l.addWidget(bb)
|
||||||
@ -70,6 +79,7 @@ class DBCheck(QDialog): # {{{
|
|||||||
l.addStretch(10)
|
l.addStretch(10)
|
||||||
self.resize(self.sizeHint())
|
self.resize(self.sizeHint())
|
||||||
self.db = weakref.ref(db.new_api)
|
self.db = weakref.ref(db.new_api)
|
||||||
|
self.setMinimumWidth(450)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.setWindowTitle(_('Vacuuming...'))
|
self.setWindowTitle(_('Vacuuming...'))
|
||||||
@ -77,12 +87,12 @@ class DBCheck(QDialog): # {{{
|
|||||||
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
|
||||||
self.vacuum_started = True
|
self.vacuum_started = True
|
||||||
db = self.db()
|
db = self.db()
|
||||||
t = self.thread = Thread(target=self.vacuum, args=(db, self.fts.isChecked()), daemon=True, name='VacuumDB')
|
t = self.thread = Thread(target=self.vacuum, args=(db, self.fts.isChecked(), self.notes.isChecked()), daemon=True, name='VacuumDB')
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
def vacuum(self, db, include_fts_db):
|
def vacuum(self, db, include_fts_db, include_notes_db):
|
||||||
try:
|
try:
|
||||||
db.vacuum(include_fts_db)
|
db.vacuum(include_fts_db, include_notes_db)
|
||||||
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