From 02b5cae577ea94816cd393dac8ccbe15260b0f66 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Fri, 9 Dec 2022 21:03:12 +0800 Subject: [PATCH] Fix #2371 by left join maintenance_timeslot --- server/model/maintenance.js | 24 +++++++++++++----------- server/model/status_page.js | 12 +++++++----- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/server/model/maintenance.js b/server/model/maintenance.js index 35030801e..d9be34273 100644 --- a/server/model/maintenance.js +++ b/server/model/maintenance.js @@ -188,13 +188,13 @@ class Maintenance extends BeanModel { */ static getActiveMaintenanceSQLCondition() { return ` - - (maintenance_timeslot.start_date <= DATETIME('now') - AND maintenance_timeslot.end_date >= DATETIME('now') - AND maintenance.active = 1) - OR - (maintenance.strategy = 'manual' AND active = 1) - + ( + (maintenance_timeslot.start_date <= DATETIME('now') + AND maintenance_timeslot.end_date >= DATETIME('now') + AND maintenance.active = 1) + OR + (maintenance.strategy = 'manual' AND active = 1) + ) `; } @@ -204,10 +204,12 @@ class Maintenance extends BeanModel { */ static getActiveAndFutureMaintenanceSQLCondition() { return ` - ((maintenance_timeslot.end_date >= DATETIME('now') - AND maintenance.active = 1) - OR - (maintenance.strategy = 'manual' AND active = 1)) + ( + ((maintenance_timeslot.end_date >= DATETIME('now') + AND maintenance.active = 1) + OR + (maintenance.strategy = 'manual' AND active = 1)) + ) `; } } diff --git a/server/model/status_page.js b/server/model/status_page.js index fbbff391f..80b576998 100644 --- a/server/model/status_page.js +++ b/server/model/status_page.js @@ -282,11 +282,13 @@ class StatusPage extends BeanModel { let activeCondition = Maintenance.getActiveMaintenanceSQLCondition(); let maintenanceBeanList = R.convertToBeans("maintenance", await R.getAll(` SELECT maintenance.* - FROM maintenance, maintenance_status_page msp, maintenance_timeslot - WHERE msp.maintenance_id = maintenance.id - AND maintenance_timeslot.maintenance_id = maintenance.id - AND msp.status_page_id = ? - AND ${activeCondition} + FROM maintenance + JOIN maintenance_status_page + ON maintenance_status_page.maintenance_id = maintenance.id + AND maintenance_status_page.status_page_id = ? + LEFT JOIN maintenance_timeslot + ON maintenance_timeslot.maintenance_id = maintenance.id + WHERE ${activeCondition} ORDER BY maintenance.end_date `, [ statusPageId ]));