lab-infra/machines/status01/unethical_patch_0.patch
Julien Malka b10fee2eee
Some checks failed
lint / check (push) Successful in 23s
build configuration / build_krz01 (push) Failing after 1m29s
feat(uptime-kuma): we have 100% uptime
2024-12-07 19:42:36 +01:00

30 lines
1.1 KiB
Diff

diff --git a/server/model/group.js b/server/model/group.js
index 5b712ace..ecbced1a 100644
--- a/server/model/group.js
+++ b/server/model/group.js
@@ -31,10 +31,23 @@ class Group extends BeanModel {
*/
async getMonitorList() {
return R.convertToBeans("monitor", await R.getAll(`
- SELECT monitor.*, monitor_group.send_url FROM monitor, monitor_group
- WHERE monitor.id = monitor_group.monitor_id
+ SELECT monitor.*, monitor_group.send_url
+ FROM monitor
+ INNER JOIN monitor_group ON monitor.id = monitor_group.monitor_id
+ WHERE monitor.id IN (
+ SELECT hb.monitor_id
+ FROM heartbeat hb
+ INNER JOIN (
+ SELECT monitor_id, MAX(time) AS latest_time
+ FROM heartbeat
+ GROUP BY monitor_id
+ ) latest_hb
+ ON hb.monitor_id = latest_hb.monitor_id AND hb.time = latest_hb.latest_time
+ WHERE hb.status = 1
+ )
AND group_id = ?
ORDER BY monitor_group.weight
+
`, [
this.id,
]));