From 74b009f658198a7366c4ffd499c91f10d247a924 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sun, 21 Jul 2024 09:04:53 +0200 Subject: [PATCH] schedule onChange optimize queue --- src/web/WebSchedulerService.cpp | 18 ++++++++++-------- src/web/WebSchedulerService.h | 6 +++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/web/WebSchedulerService.cpp b/src/web/WebSchedulerService.cpp index 34560eb6f..94843d067 100644 --- a/src/web/WebSchedulerService.cpp +++ b/src/web/WebSchedulerService.cpp @@ -422,8 +422,14 @@ bool WebSchedulerService::command(const char * name, const std::string & command #include "shuntingYard.hpp" bool WebSchedulerService::onChange(const char * cmd) { - cmd_changed_.push_back(Helpers::toLower(cmd)); - return true; + for (ScheduleItem & scheduleItem : *scheduleItems_) { + if (scheduleItem.active && scheduleItem.flags == SCHEDULEFLAG_SCHEDULE_ONCHANGE + && Helpers::toLower(scheduleItem.time).find(Helpers::toLower(cmd)) != std::string::npos) { + cmd_changed_.push_back(&scheduleItem); + return true; + } + } + return false; } void WebSchedulerService::condition() { @@ -458,12 +464,8 @@ void WebSchedulerService::loop() { // check if we have onChange events while (!cmd_changed_.empty()) { - for (const ScheduleItem & scheduleItem : *scheduleItems_) { - if (scheduleItem.active && scheduleItem.flags == SCHEDULEFLAG_SCHEDULE_ONCHANGE - && Helpers::toLower(scheduleItem.time).find(cmd_changed_.front()) != std::string::npos) { - command(scheduleItem.name.c_str(), scheduleItem.cmd, compute(scheduleItem.value)); - } - } + ScheduleItem si = *cmd_changed_.front(); + command(si.name.c_str(), si.cmd, compute(si.value)); cmd_changed_.pop_front(); } diff --git a/src/web/WebSchedulerService.h b/src/web/WebSchedulerService.h index 19b0ef32c..7e5b060fd 100644 --- a/src/web/WebSchedulerService.h +++ b/src/web/WebSchedulerService.h @@ -81,9 +81,9 @@ class WebSchedulerService : public StatefulService { HttpEndpoint _httpEndpoint; FSPersistence _fsPersistence; - std::list * scheduleItems_; // pointer to the list of schedule events - bool ha_registered_ = false; - std::deque cmd_changed_; + std::list * scheduleItems_; // pointer to the list of schedule events + bool ha_registered_ = false; + std::deque cmd_changed_; }; } // namespace emsesp