mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-01-20 03:29:25 +02:00
perf: option to only get ids of active children
This commit is contained in:
parent
0a479ecb50
commit
ec2cebc5df
@ -1701,9 +1701,29 @@ class Monitor extends BeanModel {
|
|||||||
/**
|
/**
|
||||||
* Gets recursive all children ids
|
* Gets recursive all children ids
|
||||||
* @param {number} monitorID ID of the monitor to get
|
* @param {number} monitorID ID of the monitor to get
|
||||||
|
* @param {boolean} onlyActive Return only monitors which are active (including all ancestors)
|
||||||
* @returns {Promise<number[]>} IDs of all children
|
* @returns {Promise<number[]>} IDs of all children
|
||||||
*/
|
*/
|
||||||
static async getAllChildrenIDs(monitorID) {
|
static async getAllChildrenIDs(monitorID, onlyActive = false) {
|
||||||
|
if (onlyActive) {
|
||||||
|
// Gets all children monitor ids recursive but only if they and all their ancestors are active
|
||||||
|
return await R.getCol(`
|
||||||
|
WITH RECURSIVE MonitorHierarchy(id, active_chain) AS (
|
||||||
|
SELECT id, active FROM monitor
|
||||||
|
WHERE id = ?
|
||||||
|
UNION ALL
|
||||||
|
SELECT m.id, m.active * mh.active_chain FROM monitor m
|
||||||
|
INNER JOIN MonitorHierarchy mh ON m.parent = mh.id
|
||||||
|
WHERE mh.active_chain = 1
|
||||||
|
)
|
||||||
|
SELECT id FROM MonitorHierarchy
|
||||||
|
WHERE id != ? AND active_chain = 1;
|
||||||
|
`, [
|
||||||
|
monitorID,
|
||||||
|
monitorID
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
// Gets all children monitor ids recursive
|
||||||
return await R.getCol(`
|
return await R.getCol(`
|
||||||
WITH RECURSIVE MonitorHierarchy(id) AS (
|
WITH RECURSIVE MonitorHierarchy(id) AS (
|
||||||
SELECT id FROM monitor WHERE id = ?
|
SELECT id FROM monitor WHERE id = ?
|
||||||
|
@ -1752,7 +1752,7 @@ async function startMonitor(userID, monitorID) {
|
|||||||
userID,
|
userID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const childrenIDs = await Monitor.getAllChildrenIDs(monitorID);
|
const childrenIDs = await Monitor.getAllChildrenIDs(monitorID, true);
|
||||||
const monitorIDs = [ monitorID, ...childrenIDs ];
|
const monitorIDs = [ monitorID, ...childrenIDs ];
|
||||||
|
|
||||||
let monitors = await R.find("monitor", ` id IN (${monitorIDs.map((_) => "?").join(",")})`, monitorIDs);
|
let monitors = await R.find("monitor", ` id IN (${monitorIDs.map((_) => "?").join(",")})`, monitorIDs);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user