From c1dcc0a9378d5a850dd710d4a6129f2314543020 Mon Sep 17 00:00:00 2001 From: chme Date: Sun, 21 Feb 2016 18:05:11 +0100 Subject: [PATCH] [db] Make loading of playlistitem count optional --- src/db.c | 67 +++++++++++++++++++++++++----------------------- src/db.h | 2 +- src/httpd_daap.c | 2 +- src/httpd_rsp.c | 2 +- src/mpd.c | 4 +-- 5 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/db.c b/src/db.c index f69f7abb..c362f4d9 100644 --- a/src/db.c +++ b/src/db.c @@ -1698,7 +1698,7 @@ db_query_fetch_file(struct query_params *qp, struct db_media_file_info *dbmfi) } int -db_query_fetch_pl(struct query_params *qp, struct db_playlist_info *dbpli) +db_query_fetch_pl(struct query_params *qp, struct db_playlist_info *dbpli, int with_itemcount) { int ncols; char **strcol; @@ -1751,43 +1751,46 @@ db_query_fetch_pl(struct query_params *qp, struct db_playlist_info *dbpli) *strcol = (char *)sqlite3_column_text(qp->stmt, i); } - type = sqlite3_column_int(qp->stmt, 2); - - switch (type) + if (with_itemcount) { - case PL_PLAIN: - case PL_FOLDER: - id = sqlite3_column_int(qp->stmt, 0); - nitems = db_pl_count_items(id, 0); - nstreams = db_pl_count_items(id, 1); - break; + type = sqlite3_column_int(qp->stmt, 2); - case PL_SPECIAL: - case PL_SMART: - nitems = db_smartpl_count_items(dbpli->query); - nstreams = 0; - break; + switch (type) + { + case PL_PLAIN: + case PL_FOLDER: + id = sqlite3_column_int(qp->stmt, 0); + nitems = db_pl_count_items(id, 0); + nstreams = db_pl_count_items(id, 1); + break; - default: - DPRINTF(E_LOG, L_DB, "Unknown playlist type %d while fetching playlist\n", type); - return -1; - } + case PL_SPECIAL: + case PL_SMART: + nitems = db_smartpl_count_items(dbpli->query); + nstreams = 0; + break; - dbpli->items = qp->buf1; - ret = snprintf(qp->buf1, sizeof(qp->buf1), "%d", nitems); - if ((ret < 0) || (ret >= sizeof(qp->buf1))) - { - DPRINTF(E_LOG, L_DB, "Could not convert item count, buffer too small\n"); + default: + DPRINTF(E_LOG, L_DB, "Unknown playlist type %d while fetching playlist\n", type); + return -1; + } - strcpy(qp->buf1, "0"); - } - dbpli->streams = qp->buf2; - ret = snprintf(qp->buf2, sizeof(qp->buf2), "%d", nstreams); - if ((ret < 0) || (ret >= sizeof(qp->buf2))) - { - DPRINTF(E_LOG, L_DB, "Could not convert stream count, buffer too small\n"); + dbpli->items = qp->buf1; + ret = snprintf(qp->buf1, sizeof(qp->buf1), "%d", nitems); + if ((ret < 0) || (ret >= sizeof(qp->buf1))) + { + DPRINTF(E_LOG, L_DB, "Could not convert item count, buffer too small\n"); - strcpy(qp->buf2, "0"); + strcpy(qp->buf1, "0"); + } + dbpli->streams = qp->buf2; + ret = snprintf(qp->buf2, sizeof(qp->buf2), "%d", nstreams); + if ((ret < 0) || (ret >= sizeof(qp->buf2))) + { + DPRINTF(E_LOG, L_DB, "Could not convert stream count, buffer too small\n"); + + strcpy(qp->buf2, "0"); + } } return 0; diff --git a/src/db.h b/src/db.h index e2e93ed6..65ae5eda 100644 --- a/src/db.h +++ b/src/db.h @@ -417,7 +417,7 @@ int db_query_fetch_file(struct query_params *qp, struct db_media_file_info *dbmfi); int -db_query_fetch_pl(struct query_params *qp, struct db_playlist_info *dbpli); +db_query_fetch_pl(struct query_params *qp, struct db_playlist_info *dbpli, int with_itemcount); int db_query_fetch_group(struct query_params *qp, struct db_group_info *dbgri); diff --git a/src/httpd_daap.c b/src/httpd_daap.c index 719855a1..60c8dc61 100644 --- a/src/httpd_daap.c +++ b/src/httpd_daap.c @@ -1670,7 +1670,7 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char ** } npls = 0; - while (((ret = db_query_fetch_pl(&qp, &dbpli)) == 0) && (dbpli.id)) + while (((ret = db_query_fetch_pl(&qp, &dbpli, 1)) == 0) && (dbpli.id)) { plid = 1; if (safe_atoi32(dbpli.id, &plid) != 0) diff --git a/src/httpd_rsp.c b/src/httpd_rsp.c index c9f42d8a..8e393749 100644 --- a/src/httpd_rsp.c +++ b/src/httpd_rsp.c @@ -394,7 +394,7 @@ rsp_reply_db(struct evhttp_request *req, char **uri, struct evkeyvalq *query) mxmlNewTextf(node, 0, "%d", qp.results); /* Playlists block (all playlists) */ - while (((ret = db_query_fetch_pl(&qp, &dbpli)) == 0) && (dbpli.id)) + while (((ret = db_query_fetch_pl(&qp, &dbpli, 1)) == 0) && (dbpli.id)) { /* Playlist block (one playlist) */ pl = mxmlNewElement(pls, "playlist"); diff --git a/src/mpd.c b/src/mpd.c index ac9c4f8d..85bcb945 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -2237,7 +2237,7 @@ mpd_command_listplaylists(struct evbuffer *evbuf, int argc, char **argv, char ** return ACK_ERROR_UNKNOWN; } - while (((ret = db_query_fetch_pl(&qp, &dbpli)) == 0) && (dbpli.id)) + while (((ret = db_query_fetch_pl(&qp, &dbpli, 0)) == 0) && (dbpli.id)) { if (safe_atou32(dbpli.db_timestamp, &time_modified) != 0) { @@ -2752,7 +2752,7 @@ mpd_add_directory(struct evbuffer *evbuf, int directory_id, int listall, int lis DPRINTF(E_LOG, L_MPD, "Out of memory\n"); return ACK_ERROR_UNKNOWN; } - while (((ret = db_query_fetch_pl(&qp, &dbpli)) == 0) && (dbpli.id)) + while (((ret = db_query_fetch_pl(&qp, &dbpli, 0)) == 0) && (dbpli.id)) { if (safe_atou32(dbpli.db_timestamp, &time_modified) != 0) {