From 491bf6f5e9f5c6dde5d9d1ae26d0392ec247cb9d Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Thu, 26 Sep 2024 09:40:24 +0200 Subject: rest: add free and used cache to GET /cache/list Add "used_cache" and "free_cache" fields to the payload of GET /cache/list. --- src/rest.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/rest.c b/src/rest.c index 87259cf..5ac1c3f 100644 --- a/src/rest.c +++ b/src/rest.c @@ -4130,13 +4130,14 @@ static int og_cmd_image_scope_list(json_t *element, static int og_dbi_client_cache_get(struct og_dbi *dbi, json_t *clients, const char *ip) { + uint64_t img_size, cache_size = 0, used_cache = 0, free_cache = 0; const char *img_name, *msglog, *img_checksum; json_t *client_data, *cache_arr, *img_info; - uint64_t img_size, cache_size = 0; dbi_result result; result = dbi_conn_queryf(dbi->conn, - "SELECT ordenadores_particiones.tamano " + "SELECT ordenadores_particiones.tamano, " + "ordenadores_particiones.used_size, ordenadores_particiones.free_size " "FROM ordenadores_particiones JOIN ordenadores " "ON ordenadores.idordenador = ordenadores_particiones.idordenador " "WHERE ordenadores.ip = '%s' AND codpar = 202", ip); @@ -4149,6 +4150,8 @@ static int og_dbi_client_cache_get(struct og_dbi *dbi, json_t *clients, const ch if (dbi_result_next_row(result)) { cache_size = dbi_result_get_longlong(result, "tamano") * 1024; + used_cache = dbi_result_get_longlong(result, "used_size"); + free_cache = dbi_result_get_longlong(result, "free_size"); } dbi_result_free(result); @@ -4200,6 +4203,8 @@ static int og_dbi_client_cache_get(struct og_dbi *dbi, json_t *clients, const ch json_object_set_new(client_data, "ip", json_string(ip)); json_object_set_new(client_data, "cache_size", json_integer(cache_size)); + json_object_set_new(client_data, "used_cache", json_integer(used_cache)); + json_object_set_new(client_data, "free_cache", json_integer(free_cache)); json_object_set_new(client_data, "images", cache_arr); json_array_append_new(clients, client_data); dbi_result_free(result); -- cgit v1.2.3-18-g5258