mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-23 14:54:05 +00:00
perf: option to only get ids of active children
This commit is contained in:
parent
0a479ecb50
commit
ec2cebc5df
2 changed files with 22 additions and 2 deletions
|
@ -1701,9 +1701,29 @@ class Monitor extends BeanModel {
|
|||
/**
|
||||
* Gets recursive all children ids
|
||||
* @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
|
||||
*/
|
||||
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(`
|
||||
WITH RECURSIVE MonitorHierarchy(id) AS (
|
||||
SELECT id FROM monitor WHERE id = ?
|
||||
|
|
|
@ -1752,7 +1752,7 @@ async function startMonitor(userID, monitorID) {
|
|||
userID,
|
||||
]);
|
||||
|
||||
const childrenIDs = await Monitor.getAllChildrenIDs(monitorID);
|
||||
const childrenIDs = await Monitor.getAllChildrenIDs(monitorID, true);
|
||||
const monitorIDs = [ monitorID, ...childrenIDs ];
|
||||
|
||||
let monitors = await R.find("monitor", ` id IN (${monitorIDs.map((_) => "?").join(",")})`, monitorIDs);
|
||||
|
|
Loading…
Reference in a new issue