2023-07-07 16:57:53 -04:00
|
|
|
const { R } = require("redbean-node");
|
|
|
|
const { log } = require("../../src/util");
|
2023-08-09 09:05:15 -04:00
|
|
|
const Database = require("../database");
|
2023-07-07 16:57:53 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run incremental_vacuum and checkpoint the WAL.
|
2023-08-11 03:46:41 -04:00
|
|
|
* @returns {Promise<void>} A promise that resolves when the process is finished.
|
2023-07-07 16:57:53 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
const incrementalVacuum = async () => {
|
|
|
|
try {
|
2023-08-09 09:05:15 -04:00
|
|
|
if (Database.dbConfig.type !== "sqlite") {
|
|
|
|
log.debug("incrementalVacuum", "Skipping incremental_vacuum, not using SQLite.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-07 16:57:53 -04:00
|
|
|
log.debug("incrementalVacuum", "Running incremental_vacuum and wal_checkpoint(PASSIVE)...");
|
|
|
|
await R.exec("PRAGMA incremental_vacuum(200)");
|
|
|
|
await R.exec("PRAGMA wal_checkpoint(PASSIVE)");
|
|
|
|
} catch (e) {
|
|
|
|
log.error("incrementalVacuum", `Failed: ${e.message}`);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
incrementalVacuum,
|
|
|
|
};
|