Skip to content

Commit

Permalink
Merge pull request #1877 from MichaelDvP/dev
Browse files Browse the repository at this point in the history
schedule onChange optimize queue
  • Loading branch information
proddy authored Jul 21, 2024
2 parents e4decb5 + 74b009f commit 55476a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/web/WebSchedulerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions src/web/WebSchedulerService.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
HttpEndpoint<WebScheduler> _httpEndpoint;
FSPersistence<WebScheduler> _fsPersistence;

std::list<ScheduleItem> * scheduleItems_; // pointer to the list of schedule events
bool ha_registered_ = false;
std::deque<std::string> cmd_changed_;
std::list<ScheduleItem> * scheduleItems_; // pointer to the list of schedule events
bool ha_registered_ = false;
std::deque<ScheduleItem *> cmd_changed_;
};

} // namespace emsesp
Expand Down

0 comments on commit 55476a7

Please sign in to comment.