[db] Make loading of playlistitem count optional

This commit is contained in:
chme 2016-02-21 18:05:11 +01:00
parent 29dbc6bd9d
commit c1dcc0a937
5 changed files with 40 additions and 37 deletions

View File

@ -1698,7 +1698,7 @@ db_query_fetch_file(struct query_params *qp, struct db_media_file_info *dbmfi)
} }
int 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; int ncols;
char **strcol; 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); *strcol = (char *)sqlite3_column_text(qp->stmt, i);
} }
type = sqlite3_column_int(qp->stmt, 2); if (with_itemcount)
switch (type)
{ {
case PL_PLAIN: type = sqlite3_column_int(qp->stmt, 2);
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;
case PL_SPECIAL: switch (type)
case PL_SMART: {
nitems = db_smartpl_count_items(dbpli->query); case PL_PLAIN:
nstreams = 0; case PL_FOLDER:
break; id = sqlite3_column_int(qp->stmt, 0);
nitems = db_pl_count_items(id, 0);
nstreams = db_pl_count_items(id, 1);
break;
default: case PL_SPECIAL:
DPRINTF(E_LOG, L_DB, "Unknown playlist type %d while fetching playlist\n", type); case PL_SMART:
return -1; nitems = db_smartpl_count_items(dbpli->query);
} nstreams = 0;
break;
dbpli->items = qp->buf1; default:
ret = snprintf(qp->buf1, sizeof(qp->buf1), "%d", nitems); DPRINTF(E_LOG, L_DB, "Unknown playlist type %d while fetching playlist\n", type);
if ((ret < 0) || (ret >= sizeof(qp->buf1))) return -1;
{ }
DPRINTF(E_LOG, L_DB, "Could not convert item count, buffer too small\n");
strcpy(qp->buf1, "0"); dbpli->items = qp->buf1;
} ret = snprintf(qp->buf1, sizeof(qp->buf1), "%d", nitems);
dbpli->streams = qp->buf2; if ((ret < 0) || (ret >= sizeof(qp->buf1)))
ret = snprintf(qp->buf2, sizeof(qp->buf2), "%d", nstreams); {
if ((ret < 0) || (ret >= sizeof(qp->buf2))) DPRINTF(E_LOG, L_DB, "Could not convert item count, buffer too small\n");
{
DPRINTF(E_LOG, L_DB, "Could not convert stream 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; return 0;

View File

@ -417,7 +417,7 @@ int
db_query_fetch_file(struct query_params *qp, struct db_media_file_info *dbmfi); db_query_fetch_file(struct query_params *qp, struct db_media_file_info *dbmfi);
int 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 int
db_query_fetch_group(struct query_params *qp, struct db_group_info *dbgri); db_query_fetch_group(struct query_params *qp, struct db_group_info *dbgri);

View File

@ -1670,7 +1670,7 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
} }
npls = 0; 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; plid = 1;
if (safe_atoi32(dbpli.id, &plid) != 0) if (safe_atoi32(dbpli.id, &plid) != 0)

View File

@ -394,7 +394,7 @@ rsp_reply_db(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
mxmlNewTextf(node, 0, "%d", qp.results); mxmlNewTextf(node, 0, "%d", qp.results);
/* Playlists block (all playlists) */ /* 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) */ /* Playlist block (one playlist) */
pl = mxmlNewElement(pls, "playlist"); pl = mxmlNewElement(pls, "playlist");

View File

@ -2237,7 +2237,7 @@ mpd_command_listplaylists(struct evbuffer *evbuf, int argc, char **argv, char **
return ACK_ERROR_UNKNOWN; 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) 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"); DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_UNKNOWN; 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) if (safe_atou32(dbpli.db_timestamp, &time_modified) != 0)
{ {