mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-23 23:04:04 +00:00
feat: db statement to get all active monitors
This commit is contained in:
parent
22dcba17c8
commit
71c7ee69c7
2 changed files with 19 additions and 2 deletions
|
@ -1608,6 +1608,24 @@ class Monitor extends BeanModel {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all active monitors
|
||||||
|
* @returns {Promise<Bean[]>} Active Monitors
|
||||||
|
*/
|
||||||
|
static async getAllActiveMonitors() {
|
||||||
|
return R.convertToBeans("monitor", await R.getAll(`
|
||||||
|
WITH RECURSIVE MonitorHierarchy AS (
|
||||||
|
SELECT * FROM monitor
|
||||||
|
WHERE parent IS NULL AND active = 1
|
||||||
|
UNION ALL
|
||||||
|
SELECT m.* FROM monitor m
|
||||||
|
INNER JOIN MonitorHierarchy mh ON m.parent = mh.id
|
||||||
|
WHERE m.active = 1
|
||||||
|
)
|
||||||
|
SELECT * FROM MonitorHierarchy;
|
||||||
|
`));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets Parent of the monitor
|
* Gets Parent of the monitor
|
||||||
* @param {number} monitorID ID of monitor to get
|
* @param {number} monitorID ID of monitor to get
|
||||||
|
|
|
@ -1810,8 +1810,7 @@ async function pauseMonitor(userID, monitorID) {
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async function startMonitors() {
|
async function startMonitors() {
|
||||||
let list = await R.find("monitor", " active = 1 ");
|
let list = await Monitor.getAllActiveMonitors();
|
||||||
list = list.filter((monitor) => Monitor.isActive(monitor.id, monitor.active));
|
|
||||||
|
|
||||||
for (let monitor of list) {
|
for (let monitor of list) {
|
||||||
server.monitorList[monitor.id] = monitor;
|
server.monitorList[monitor.id] = monitor;
|
||||||
|
|
Loading…
Reference in a new issue