Wait for an open transaction before vacuuming the embeddings database

SQLite can't vacuum from within a transaction, and the idle handler that
vacuums the attached database can run while other work has one open.
This commit is contained in:
Dan Stillman 2026-07-30 21:39:13 -04:00
parent b45f1c751e
commit 4a70708e07

View file

@ -304,6 +304,9 @@ Zotero.Embeddings = new function () {
* @return {Promise<Boolean>} - Whether the database was vacuumed
*/
this.vacuumDB = async function ({ force = false } = {}) {
if (Zotero.DB.inTransaction()) {
await Zotero.DB.waitForTransaction();
}
if (!force) {
let freelistCount = await Zotero.DB.valueQueryAsync("PRAGMA embeddings.freelist_count");
let pageCount = await Zotero.DB.valueQueryAsync("PRAGMA embeddings.page_count");