mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-18 04:04:41 -05:00
Feat: Run incremental_vacuum and optimize
This commit is contained in:
parent
19873e5b9e
commit
9954ba82e7
@ -1,5 +1,6 @@
|
|||||||
const { UptimeKumaServer } = require("./uptime-kuma-server");
|
const { UptimeKumaServer } = require("./uptime-kuma-server");
|
||||||
const { clearOldData } = require("./jobs/clear-old-data");
|
const { clearOldData } = require("./jobs/clear-old-data");
|
||||||
|
const { incrementalVacuum } = require("./jobs/incremental-vacuum");
|
||||||
const Cron = require("croner");
|
const Cron = require("croner");
|
||||||
|
|
||||||
const jobs = [
|
const jobs = [
|
||||||
@ -9,6 +10,12 @@ const jobs = [
|
|||||||
jobFunc: clearOldData,
|
jobFunc: clearOldData,
|
||||||
croner: null,
|
croner: null,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "incremental-vacuum",
|
||||||
|
interval: "*/5 * * * *",
|
||||||
|
jobFunc: incrementalVacuum,
|
||||||
|
croner: null,
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,6 +39,8 @@ const clearOldData = async () => {
|
|||||||
"DELETE FROM heartbeat WHERE time < DATETIME('now', '-' || ? || ' days') ",
|
"DELETE FROM heartbeat WHERE time < DATETIME('now', '-' || ? || ' days') ",
|
||||||
[ parsedPeriod ]
|
[ parsedPeriod ]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await R.exec("PRAGMA optimize;");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error("clearOldData", `Failed to clear old data: ${e.message}`);
|
log.error("clearOldData", `Failed to clear old data: ${e.message}`);
|
||||||
}
|
}
|
||||||
|
21
server/jobs/incremental-vacuum.js
Normal file
21
server/jobs/incremental-vacuum.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
const { R } = require("redbean-node");
|
||||||
|
const { log } = require("../../src/util");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run incremental_vacuum and checkpoint the WAL.
|
||||||
|
* @return {Promise<void>} A promise that resolves when the process is finished.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const incrementalVacuum = async () => {
|
||||||
|
try {
|
||||||
|
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,
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user