fix: use separate relay caches for status

This commit is contained in:
Tobias Reisinger 2020-08-25 12:39:43 +02:00
parent 0eef646fe0
commit f98a01f3f0
13 changed files with 49 additions and 38 deletions

View file

@ -273,7 +273,7 @@ controller_to_json(controller_t *controller)
cJSON *json_relays = cJSON_CreateArray();
for(int i = 0; relays[i] != NULL; ++i)
{
cJSON *json_relay = relay_to_json(relays[i]);
cJSON *json_relay = relay_to_json(relays[i], 0);
cJSON_AddItemToArray(json_relays, json_relay);
}
cJSON_AddItemToObject(json, "relays", json_relays);

View file

@ -47,7 +47,7 @@ junction_tag_insert(int tag_id, int relay_id, int schedule_id)
if(relay_id)
{
cache_invalidate_relay(relay_id);
cache_invalidate_relay(relay_id, -1);
}
if(schedule_id)
{
@ -116,7 +116,7 @@ junction_tag_insert_list(int *tag_ids, int relay_id, int schedule_id, int count)
if(relay_id)
{
cache_invalidate_relay(relay_id);
cache_invalidate_relay(relay_id, -1);
}
if(schedule_id)
{
@ -185,7 +185,7 @@ junction_tag_remove(int tag_id, int relay_id, int schedule_id)
if(relay_id)
{
cache_invalidate_relay(relay_id);
cache_invalidate_relay(relay_id, -1);
}
if(schedule_id)
{
@ -206,7 +206,7 @@ junction_tag_remove_for_relay(int relay_id)
rc = sqlite3_step(stmt);
sqlite3_finalize(stmt);
cache_invalidate_relay(relay_id);
cache_invalidate_relay(relay_id, -1);
return rc == SQLITE_DONE;
}

View file

@ -169,7 +169,7 @@ relay_save(relay_t *relay)
}
}
cache_invalidate_relay(relay->id);
cache_invalidate_relay(relay->id, -1);
status_reload_entry(relay->id);
return result;
@ -236,11 +236,11 @@ relay_free_list(relay_t **relays)
}
cJSON*
relay_to_json(relay_t *relay)
relay_to_json(relay_t *relay, int status_relay)
{
cJSON *json;
char *cached = cache_get_json_relay(relay->id);
char *cached = cache_get_json_relay(relay->id, status_relay);
if(cached)
{
json = cJSON_CreateRaw(cached);
@ -345,7 +345,7 @@ relay_to_json(relay_t *relay)
cJSON_AddItemToObject(json, "tags", json_tags);
char *json_str = cJSON_Print(json);
cache_put_json_relay(relay->id, json_str);
cache_put_json_relay(relay->id, status_relay, json_str);
cJSON_Delete(json);
json = cJSON_CreateRaw(json_str);
@ -354,13 +354,13 @@ relay_to_json(relay_t *relay)
}
cJSON*
relay_list_to_json(relay_t **relays)
relay_list_to_json(relay_t **relays, int status_relays)
{
cJSON *json = cJSON_CreateArray();
for(int i = 0; relays[i] != NULL; ++i)
{
cJSON *json_relay = relay_to_json(relays[i]);
cJSON *json_relay = relay_to_json(relays[i], status_relays);
cJSON_AddItemToArray(json, json_relay);
}