This commit is contained in:
Louis Lam 2023-03-07 20:47:57 +08:00
parent 65933de0cd
commit 2dedc1cfbd
3 changed files with 6 additions and 0 deletions

View File

View File

@ -41,6 +41,8 @@ class MaintenanceTimeslot extends BeanModel {
* @returns {Promise<MaintenanceTimeslot>} * @returns {Promise<MaintenanceTimeslot>}
*/ */
static async generateTimeslot(maintenance, minDate = null, removeExist = false) { static async generateTimeslot(maintenance, minDate = null, removeExist = false) {
log.info("maintenance", "Generate Timeslot for maintenance id: " + maintenance.id);
if (removeExist) { if (removeExist) {
await R.exec("DELETE FROM maintenance_timeslot WHERE maintenance_id = ? ", [ await R.exec("DELETE FROM maintenance_timeslot WHERE maintenance_id = ? ", [
maintenance.id maintenance.id

View File

@ -272,6 +272,10 @@ class UptimeKumaServer {
/** Load the timeslots for maintenance */ /** Load the timeslots for maintenance */
async generateMaintenanceTimeslots() { async generateMaintenanceTimeslots() {
// Prevent #2776
// Remove duplicate maintenance_timeslot with same start_date, end_date and maintenance_id
await R.exec("DELETE FROM maintenance_timeslot WHERE id NOT IN (SELECT MIN(id) FROM maintenance_timeslot GROUP BY start_date, end_date, maintenance_id)");
let list = await R.find("maintenance_timeslot", " generated_next = 0 AND start_date <= DATETIME('now') "); let list = await R.find("maintenance_timeslot", " generated_next = 0 AND start_date <= DATETIME('now') ");
for (let maintenanceTimeslot of list) { for (let maintenanceTimeslot of list) {