fix: load less from database on mqtt publish
This commit is contained in:
parent
6117548e32
commit
6728ef9264
6 changed files with 40 additions and 25 deletions
src/handlers
|
@ -31,13 +31,12 @@ handle_mqtt_publish_controller(char **topic_save, int controller_id, char *paylo
|
|||
{
|
||||
return;
|
||||
}
|
||||
relay_t *relay = relay_get_for_controller(controller_id, relay_num);
|
||||
if(!relay)
|
||||
int relay_id = relay_get_id_for_controller(controller_id, relay_num);
|
||||
if(!relay_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
status_update_entry(relay->id, payload[0] == '1');
|
||||
free(relay);
|
||||
status_update_entry(relay_id, payload[0] == '1');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,11 +63,10 @@ handle_mqtt_publish(struct mg_mqtt_message *msg)
|
|||
uuid_t controller_uid;
|
||||
if(uuid_parse(controller_uid_str, controller_uid) == 0)
|
||||
{
|
||||
controller_t *controller = controller_get_by_uid(controller_uid);
|
||||
if(controller)
|
||||
int controller_id = controller_get_id_for_uid(controller_uid);
|
||||
if(controller_id)
|
||||
{
|
||||
handle_mqtt_publish_controller(topic_save, controller->id, payload);
|
||||
controller_free(controller);
|
||||
handle_mqtt_publish_controller(topic_save, controller_id, payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue