[jsonapi] Add cache control header to count endpoint and fix

not-modified-since check to check against the last db update instead of
last start time
This commit is contained in:
chme 2018-04-27 06:42:57 +02:00 committed by ejurgensen
parent 41e99ca3cd
commit 85257788ba
2 changed files with 15 additions and 11 deletions

View File

@ -1834,7 +1834,7 @@ db_build_query_count_items(struct query_params *qp)
qp->results = 1; qp->results = 1;
query = sqlite3_mprintf("SELECT COUNT(*), SUM(song_length), COUNT(distinct songartistid), COUNT(distinct songalbumid) FROM files f %s;", qc->where); query = sqlite3_mprintf("SELECT COUNT(*), SUM(song_length), COUNT(DISTINCT songartistid), COUNT(DISTINCT songalbumid) FROM files f %s;", qc->where);
if (!query) if (!query)
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n"); DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");

View File

@ -31,7 +31,6 @@
#endif #endif
#include <regex.h> #include <regex.h>
#include <sqlite3.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
@ -1895,7 +1894,7 @@ jsonapi_reply_library_artists(struct httpd_request *hreq)
int total; int total;
int ret = 0; int ret = 0;
db_update = (time_t) db_admin_getint64(DB_ADMIN_START_TIME); db_update = (time_t) db_admin_getint64(DB_ADMIN_DB_UPDATE);
if (db_update && httpd_request_not_modified_since(hreq->req, &db_update)) if (db_update && httpd_request_not_modified_since(hreq->req, &db_update))
return HTTP_NOTMODIFIED; return HTTP_NOTMODIFIED;
@ -1957,7 +1956,7 @@ jsonapi_reply_library_artist(struct httpd_request *hreq)
json_object *reply; json_object *reply;
int ret = 0; int ret = 0;
db_update = (time_t) db_admin_getint64(DB_ADMIN_START_TIME); db_update = (time_t) db_admin_getint64(DB_ADMIN_DB_UPDATE);
if (db_update && httpd_request_not_modified_since(hreq->req, &db_update)) if (db_update && httpd_request_not_modified_since(hreq->req, &db_update))
return HTTP_NOTMODIFIED; return HTTP_NOTMODIFIED;
@ -1995,7 +1994,7 @@ jsonapi_reply_library_artist_albums(struct httpd_request *hreq)
int total; int total;
int ret = 0; int ret = 0;
db_update = (time_t) db_admin_getint64(DB_ADMIN_START_TIME); db_update = (time_t) db_admin_getint64(DB_ADMIN_DB_UPDATE);
if (db_update && httpd_request_not_modified_since(hreq->req, &db_update)) if (db_update && httpd_request_not_modified_since(hreq->req, &db_update))
return HTTP_NOTMODIFIED; return HTTP_NOTMODIFIED;
@ -2051,7 +2050,7 @@ jsonapi_reply_library_albums(struct httpd_request *hreq)
int total; int total;
int ret = 0; int ret = 0;
db_update = (time_t) db_admin_getint64(DB_ADMIN_START_TIME); db_update = (time_t) db_admin_getint64(DB_ADMIN_DB_UPDATE);
if (db_update && httpd_request_not_modified_since(hreq->req, &db_update)) if (db_update && httpd_request_not_modified_since(hreq->req, &db_update))
return HTTP_NOTMODIFIED; return HTTP_NOTMODIFIED;
@ -2113,7 +2112,7 @@ jsonapi_reply_library_album(struct httpd_request *hreq)
json_object *reply; json_object *reply;
int ret = 0; int ret = 0;
db_update = (time_t) db_admin_getint64(DB_ADMIN_START_TIME); db_update = (time_t) db_admin_getint64(DB_ADMIN_DB_UPDATE);
if (db_update && httpd_request_not_modified_since(hreq->req, &db_update)) if (db_update && httpd_request_not_modified_since(hreq->req, &db_update))
return HTTP_NOTMODIFIED; return HTTP_NOTMODIFIED;
@ -2151,7 +2150,7 @@ jsonapi_reply_library_album_tracks(struct httpd_request *hreq)
int total; int total;
int ret = 0; int ret = 0;
db_update = (time_t) db_admin_getint64(DB_ADMIN_START_TIME); db_update = (time_t) db_admin_getint64(DB_ADMIN_DB_UPDATE);
if (db_update && httpd_request_not_modified_since(hreq->req, &db_update)) if (db_update && httpd_request_not_modified_since(hreq->req, &db_update))
return HTTP_NOTMODIFIED; return HTTP_NOTMODIFIED;
@ -2205,7 +2204,7 @@ jsonapi_reply_library_playlists(struct httpd_request *hreq)
int total; int total;
int ret = 0; int ret = 0;
db_update = (time_t) db_admin_getint64(DB_ADMIN_START_TIME); db_update = (time_t) db_admin_getint64(DB_ADMIN_DB_UPDATE);
if (db_update && httpd_request_not_modified_since(hreq->req, &db_update)) if (db_update && httpd_request_not_modified_since(hreq->req, &db_update))
return HTTP_NOTMODIFIED; return HTTP_NOTMODIFIED;
@ -2255,7 +2254,7 @@ jsonapi_reply_library_playlist(struct httpd_request *hreq)
json_object *reply; json_object *reply;
int ret = 0; int ret = 0;
db_update = (time_t) db_admin_getint64(DB_ADMIN_START_TIME); db_update = (time_t) db_admin_getint64(DB_ADMIN_DB_UPDATE);
if (db_update && httpd_request_not_modified_since(hreq->req, &db_update)) if (db_update && httpd_request_not_modified_since(hreq->req, &db_update))
return HTTP_NOTMODIFIED; return HTTP_NOTMODIFIED;
@ -2293,7 +2292,7 @@ jsonapi_reply_library_playlist_tracks(struct httpd_request *hreq)
int total; int total;
int ret = 0; int ret = 0;
db_update = (time_t) db_admin_getint64(DB_ADMIN_START_TIME); db_update = (time_t) db_admin_getint64(DB_ADMIN_DB_UPDATE);
if (db_update && httpd_request_not_modified_since(hreq->req, &db_update)) if (db_update && httpd_request_not_modified_since(hreq->req, &db_update))
return HTTP_NOTMODIFIED; return HTTP_NOTMODIFIED;
@ -2343,6 +2342,7 @@ jsonapi_reply_library_playlist_tracks(struct httpd_request *hreq)
static int static int
jsonapi_reply_library_count(struct httpd_request *hreq) jsonapi_reply_library_count(struct httpd_request *hreq)
{ {
time_t db_update;
const char *param_expression; const char *param_expression;
char *expression; char *expression;
struct smartpl smartpl_expression; struct smartpl smartpl_expression;
@ -2352,6 +2352,10 @@ jsonapi_reply_library_count(struct httpd_request *hreq)
int ret; int ret;
db_update = (time_t) db_admin_getint64(DB_ADMIN_DB_UPDATE);
if (db_update && httpd_request_not_modified_since(hreq->req, &db_update))
return HTTP_NOTMODIFIED;
memset(&qp, 0, sizeof(struct query_params)); memset(&qp, 0, sizeof(struct query_params));
qp.type = Q_COUNT_ITEMS; qp.type = Q_COUNT_ITEMS;