lab-infra/machines/status01/unethical_patch_0.patch

31 lines
1.1 KiB
Diff
Raw Normal View History

2024-12-07 19:42:36 +01:00
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,
]));