diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index dee198bfb0..f5ee4fad40 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -1462,8 +1462,11 @@ class DB: finally: self.reopen() - def vacuum(self, include_fts_db, include_notes_db): + def vacuum(self, include_fts_db, include_notes_db, rebuild_annotations_fts): self.execute('VACUUM') + if rebuild_annotations_fts: + self.execute('INSERT INTO annotations_fts(annotations_fts) VALUES("rebuild");') + self.execute('INSERT INTO annotations_fts_stemmed(annotations_fts_stemmed) VALUES("rebuild");') if self.fts_enabled and include_fts_db: self.fts.vacuum() if include_notes_db: diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index ad7aa79fc8..146192c008 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -2999,10 +2999,10 @@ class Cache: return self.backend.dump_and_restore(callback=callback, sql=sql) @write_api - def vacuum(self, include_fts_db=False, include_notes_db=True): + def vacuum(self, include_fts_db=False, include_notes_db=True, rebuild_annotations_fts=False): self.is_doing_rebuild_or_vacuum = True try: - self.backend.vacuum(include_fts_db, include_notes_db) + self.backend.vacuum(include_fts_db, include_notes_db, rebuild_annotations_fts) finally: self.is_doing_rebuild_or_vacuum = False diff --git a/src/calibre/gui2/dialogs/check_library.py b/src/calibre/gui2/dialogs/check_library.py index e7b3281278..a96dc3a0a0 100644 --- a/src/calibre/gui2/dialogs/check_library.py +++ b/src/calibre/gui2/dialogs/check_library.py @@ -64,6 +64,13 @@ class DBCheck(QDialog): # {{{ la.setWordWrap(True) l.addWidget(la) + self.annots = a = QCheckBox(_('Also rebuild the annotations search index')) + l.addWidget(a) + la = QLabel('
' + _( + 'This can be a slow operation, depending on the number of annotations you have.')) + la.setWordWrap(True) + l.addWidget(la) + self.fts = f = QCheckBox(_('Also compact the Full text search database')) l.addWidget(f) la = QLabel('
' + _( @@ -106,12 +113,13 @@ class DBCheck(QDialog): # {{{ QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor)) self.vacuum_started = True db = self.db() - t = self.thread = Thread(target=self.vacuum, args=(db, self.fts.isChecked(), self.notes.isChecked()), daemon=True, name='VacuumDB') + t = self.thread = Thread(target=self.vacuum, args=( + db, self.fts.isChecked(), self.notes.isChecked(), self.annots.isChecked()), daemon=True, name='VacuumDB') t.start() - def vacuum(self, db, include_fts_db, include_notes_db): + def vacuum(self, db, include_fts_db, include_notes_db, rebuild_annotations_fts): try: - db.vacuum(include_fts_db, include_notes_db) + db.vacuum(include_fts_db, include_notes_db, rebuild_annotations_fts) except Exception as e: import traceback self.error = (as_unicode(e), traceback.format_exc())