mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-29 08:33:23 -05:00
Maintain songalbumid inside the files table
songalbumid is used a lot in queries from Remote; computing the hash for each row is a major waste of time on big libraries and slow machines, so let's store the hash in the table. This brings us to schema version 7.
This commit is contained in:
parent
20c57d5289
commit
748cca63be
@ -41,7 +41,7 @@ static struct dmap_query_field_map dmap_query_fields[] =
|
|||||||
{ 0, 0, "dmap.itemname", "title" },
|
{ 0, 0, "dmap.itemname", "title" },
|
||||||
{ 0, 1, "dmap.itemid", "id" },
|
{ 0, 1, "dmap.itemid", "id" },
|
||||||
{ 0, 0, "daap.songalbum", "album" },
|
{ 0, 0, "daap.songalbum", "album" },
|
||||||
{ 0, 1, "daap.songalbumid", "daap_songalbumid(album_artist, album)" },
|
{ 0, 1, "daap.songalbumid", "songalbumid" },
|
||||||
{ 0, 0, "daap.songartist", "artist" },
|
{ 0, 0, "daap.songartist", "artist" },
|
||||||
{ 0, 1, "daap.songbitrate", "bitrate" },
|
{ 0, 1, "daap.songbitrate", "bitrate" },
|
||||||
{ 0, 0, "daap.songcomment", "comment" },
|
{ 0, 0, "daap.songcomment", "comment" },
|
||||||
|
31
src/db.c
31
src/db.c
@ -106,6 +106,7 @@ static struct col_type_map mfi_cols_map[] =
|
|||||||
{ mfi_offsetof(tv_network_name), DB_TYPE_STRING },
|
{ mfi_offsetof(tv_network_name), DB_TYPE_STRING },
|
||||||
{ mfi_offsetof(tv_episode_sort), DB_TYPE_INT },
|
{ mfi_offsetof(tv_episode_sort), DB_TYPE_INT },
|
||||||
{ mfi_offsetof(tv_season_num), DB_TYPE_INT },
|
{ mfi_offsetof(tv_season_num), DB_TYPE_INT },
|
||||||
|
{ mfi_offsetof(songalbumid), DB_TYPE_INT64 },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This list must be kept in sync with
|
/* This list must be kept in sync with
|
||||||
@ -181,6 +182,7 @@ static ssize_t dbmfi_cols_map[] =
|
|||||||
dbmfi_offsetof(tv_network_name),
|
dbmfi_offsetof(tv_network_name),
|
||||||
dbmfi_offsetof(tv_episode_sort),
|
dbmfi_offsetof(tv_episode_sort),
|
||||||
dbmfi_offsetof(tv_season_num),
|
dbmfi_offsetof(tv_season_num),
|
||||||
|
dbmfi_offsetof(songalbumid),
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This list must be kept in sync with
|
/* This list must be kept in sync with
|
||||||
@ -719,7 +721,7 @@ db_build_query_groups(struct query_params *qp, char **q)
|
|||||||
char *idx;
|
char *idx;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
qp->results = db_get_count("SELECT COUNT(DISTINCT daap_songalbumid(album_artist, album)) FROM files WHERE disabled = 0;");
|
qp->results = db_get_count("SELECT COUNT(DISTINCT songalbumid) FROM files WHERE disabled = 0;");
|
||||||
if (qp->results < 0)
|
if (qp->results < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -729,13 +731,13 @@ db_build_query_groups(struct query_params *qp, char **q)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (idx && qp->filter)
|
if (idx && qp->filter)
|
||||||
query = sqlite3_mprintf("SELECT COUNT(*) AS items, daap_songalbumid(album_artist, album) AS persistentid, album_artist, album FROM files GROUP BY album_artist, album HAVING disabled = 0 AND %s %s;", qp->filter, idx);
|
query = sqlite3_mprintf("SELECT COUNT(*) AS items, songalbumid AS persistentid, album_artist, album FROM files GROUP BY album_artist, album HAVING disabled = 0 AND %s %s;", qp->filter, idx);
|
||||||
else if (idx)
|
else if (idx)
|
||||||
query = sqlite3_mprintf("SELECT COUNT(*) AS items, daap_songalbumid(album_artist, album) AS persistentid, album_artist, album FROM files GROUP BY album_artist, album HAVING disabled = 0 %s;", idx);
|
query = sqlite3_mprintf("SELECT COUNT(*) AS items, songalbumid AS persistentid, album_artist, album FROM files GROUP BY album_artist, album HAVING disabled = 0 %s;", idx);
|
||||||
else if (qp->filter)
|
else if (qp->filter)
|
||||||
query = sqlite3_mprintf("SELECT COUNT(*) AS items, daap_songalbumid(album_artist, album) AS persistentid, album_artist, album FROM files GROUP BY album_artist, album HAVING disabled = 0 AND %s;", qp->filter);
|
query = sqlite3_mprintf("SELECT COUNT(*) AS items, songalbumid AS persistentid, album_artist, album FROM files GROUP BY album_artist, album HAVING disabled = 0 AND %s;", qp->filter);
|
||||||
else
|
else
|
||||||
query = sqlite3_mprintf("SELECT COUNT(*) AS items, daap_songalbumid(album_artist, album) AS persistentid, album_artist, album FROM files GROUP BY album_artist, album HAVING disabled = 0;");
|
query = sqlite3_mprintf("SELECT COUNT(*) AS items, songalbumid AS persistentid, album_artist, album FROM files GROUP BY album_artist, album HAVING disabled = 0;");
|
||||||
|
|
||||||
if (!query)
|
if (!query)
|
||||||
{
|
{
|
||||||
@ -1503,13 +1505,14 @@ db_file_add(struct media_file_info *mfi)
|
|||||||
" total_tracks, disc, total_discs, bpm, compilation, rating, play_count, data_kind, item_kind," \
|
" total_tracks, disc, total_discs, bpm, compilation, rating, play_count, data_kind, item_kind," \
|
||||||
" description, time_added, time_modified, time_played, db_timestamp, disabled, sample_count," \
|
" description, time_added, time_modified, time_played, db_timestamp, disabled, sample_count," \
|
||||||
" codectype, idx, has_video, contentrating, bits_per_sample, album_artist," \
|
" codectype, idx, has_video, contentrating, bits_per_sample, album_artist," \
|
||||||
" media_kind, tv_series_name, tv_episode_num_str, tv_network_name, tv_episode_sort, tv_season_num " \
|
" media_kind, tv_series_name, tv_episode_num_str, tv_network_name, tv_episode_sort, tv_season_num, " \
|
||||||
|
" songalbumid" \
|
||||||
" ) " \
|
" ) " \
|
||||||
" VALUES (NULL, '%q', '%q', %Q, %Q, %Q, %Q, %Q, %Q, %Q," \
|
" VALUES (NULL, '%q', '%q', %Q, %Q, %Q, %Q, %Q, %Q, %Q," \
|
||||||
" %Q, %Q, %Q, %Q, %d, %d, %d, %" PRIi64 ", %d, %d," \
|
" %Q, %Q, %Q, %Q, %d, %d, %d, %" PRIi64 ", %d, %d," \
|
||||||
" %d, %d, %d, %d, %d, %d, %d, %d, %d," \
|
" %d, %d, %d, %d, %d, %d, %d, %d, %d," \
|
||||||
" %Q, %" PRIi64 ", %" PRIi64 ", %" PRIi64 ", %" PRIi64 ", %d, %" PRIi64 "," \
|
" %Q, %" PRIi64 ", %" PRIi64 ", %" PRIi64 ", %" PRIi64 ", %d, %" PRIi64 "," \
|
||||||
" %Q, %d, %d, %d, %d, %Q, %d, %Q, %Q, %Q, %d, %d);"
|
" %Q, %d, %d, %d, %d, %Q, %d, %Q, %Q, %Q, %d, %d, daap_songalbumid(%Q, %Q));"
|
||||||
char *query;
|
char *query;
|
||||||
char *errmsg;
|
char *errmsg;
|
||||||
int ret;
|
int ret;
|
||||||
@ -1539,7 +1542,8 @@ db_file_add(struct media_file_info *mfi)
|
|||||||
mfi->codectype, mfi->index, mfi->has_video,
|
mfi->codectype, mfi->index, mfi->has_video,
|
||||||
mfi->contentrating, mfi->bits_per_sample, mfi->album_artist,
|
mfi->contentrating, mfi->bits_per_sample, mfi->album_artist,
|
||||||
mfi->media_kind, mfi->tv_series_name, mfi->tv_episode_num_str,
|
mfi->media_kind, mfi->tv_series_name, mfi->tv_episode_num_str,
|
||||||
mfi->tv_network_name, mfi->tv_episode_sort, mfi->tv_season_num);
|
mfi->tv_network_name, mfi->tv_episode_sort, mfi->tv_season_num,
|
||||||
|
mfi->album_artist, mfi->album);
|
||||||
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");
|
||||||
@ -1579,7 +1583,8 @@ db_file_update(struct media_file_info *mfi)
|
|||||||
" codectype = %Q, idx = %d, has_video = %d," \
|
" codectype = %Q, idx = %d, has_video = %d," \
|
||||||
" bits_per_sample = %d, album_artist = %Q," \
|
" bits_per_sample = %d, album_artist = %Q," \
|
||||||
" media_kind = %d, tv_series_name = %Q, tv_episode_num_str = %Q," \
|
" media_kind = %d, tv_series_name = %Q, tv_episode_num_str = %Q," \
|
||||||
" tv_network_name = %Q, tv_episode_sort = %d, tv_season_num = %d" \
|
" tv_network_name = %Q, tv_episode_sort = %d, tv_season_num = %d," \
|
||||||
|
" songalbumid = daap_songalbumid(%Q, %Q) " \
|
||||||
" WHERE id = %d;"
|
" WHERE id = %d;"
|
||||||
char *query;
|
char *query;
|
||||||
char *errmsg;
|
char *errmsg;
|
||||||
@ -1608,6 +1613,7 @@ db_file_update(struct media_file_info *mfi)
|
|||||||
mfi->bits_per_sample, mfi->album_artist,
|
mfi->bits_per_sample, mfi->album_artist,
|
||||||
mfi->media_kind, mfi->tv_series_name, mfi->tv_episode_num_str,
|
mfi->media_kind, mfi->tv_series_name, mfi->tv_episode_num_str,
|
||||||
mfi->tv_network_name, mfi->tv_episode_sort, mfi->tv_season_num,
|
mfi->tv_network_name, mfi->tv_episode_sort, mfi->tv_season_num,
|
||||||
|
mfi->album_artist, mfi->album,
|
||||||
mfi->id);
|
mfi->id);
|
||||||
|
|
||||||
if (!query)
|
if (!query)
|
||||||
@ -3151,7 +3157,8 @@ db_perthread_deinit(void)
|
|||||||
" tv_episode_num_str VARCHAR(1024) DEFAULT NULL," \
|
" tv_episode_num_str VARCHAR(1024) DEFAULT NULL," \
|
||||||
" tv_network_name VARCHAR(1024) DEFAULT NULL," \
|
" tv_network_name VARCHAR(1024) DEFAULT NULL," \
|
||||||
" tv_episode_sort INTEGER NOT NULL," \
|
" tv_episode_sort INTEGER NOT NULL," \
|
||||||
" tv_season_num INTEGER NOT NULL" \
|
" tv_season_num INTEGER NOT NULL," \
|
||||||
|
" songalbumid INTEGER NOT NULL" \
|
||||||
");"
|
");"
|
||||||
|
|
||||||
#define T_PL \
|
#define T_PL \
|
||||||
@ -3226,9 +3233,9 @@ db_perthread_deinit(void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define SCHEMA_VERSION 6
|
#define SCHEMA_VERSION 7
|
||||||
#define Q_SCVER \
|
#define Q_SCVER \
|
||||||
"INSERT INTO admin (key, value) VALUES ('schema_version', '6');"
|
"INSERT INTO admin (key, value) VALUES ('schema_version', '7');"
|
||||||
|
|
||||||
struct db_init_query {
|
struct db_init_query {
|
||||||
char *query;
|
char *query;
|
||||||
|
3
src/db.h
3
src/db.h
@ -117,6 +117,8 @@ struct media_file_info {
|
|||||||
char *tv_network_name;
|
char *tv_network_name;
|
||||||
|
|
||||||
char *album_artist;
|
char *album_artist;
|
||||||
|
|
||||||
|
int64_t songalbumid;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define mfi_offsetof(field) offsetof(struct media_file_info, field)
|
#define mfi_offsetof(field) offsetof(struct media_file_info, field)
|
||||||
@ -226,6 +228,7 @@ struct db_media_file_info {
|
|||||||
char *tv_series_name;
|
char *tv_series_name;
|
||||||
char *tv_episode_num_str;
|
char *tv_episode_num_str;
|
||||||
char *tv_network_name;
|
char *tv_network_name;
|
||||||
|
char *songalbumid;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define dbmfi_offsetof(field) offsetof(struct db_media_file_info, field)
|
#define dbmfi_offsetof(field) offsetof(struct db_media_file_info, field)
|
||||||
|
@ -347,8 +347,8 @@ static struct dmap_field_map dmap_fields[] =
|
|||||||
-1, -1, -1 },
|
-1, -1, -1 },
|
||||||
{ 0, &dmap_asal,
|
{ 0, &dmap_asal,
|
||||||
dbmfi_offsetof(album), -1, -1 },
|
dbmfi_offsetof(album), -1, -1 },
|
||||||
{ 0, &dmap_asai, /* special case; will be transformed to LONG (hash) */
|
{ 0, &dmap_asai,
|
||||||
dbmfi_offsetof(album), -1, -1 },
|
dbmfi_offsetof(songalbumid), -1, -1 },
|
||||||
{ 0, &dmap_asaa,
|
{ 0, &dmap_asaa,
|
||||||
dbmfi_offsetof(album_artist), -1, dbgri_offsetof(songalbumartist) },
|
dbmfi_offsetof(album_artist), -1, dbgri_offsetof(songalbumartist) },
|
||||||
{ 0, &dmap_asar,
|
{ 0, &dmap_asar,
|
||||||
@ -1305,7 +1305,6 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
char **strval;
|
char **strval;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
uint32_t *meta;
|
uint32_t *meta;
|
||||||
int64_t songalbumid;
|
|
||||||
int nmeta;
|
int nmeta;
|
||||||
int nsongs;
|
int nsongs;
|
||||||
int transcode;
|
int transcode;
|
||||||
@ -1486,19 +1485,6 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Special handling for songalbumid (asai)
|
|
||||||
* Return an int64_t hash of the album_artist & album
|
|
||||||
*/
|
|
||||||
if (dfm->field == &dmap_asai)
|
|
||||||
{
|
|
||||||
songalbumid = daap_songalbumid(dbmfi.album_artist, dbmfi.album);
|
|
||||||
|
|
||||||
dmap_add_long(song, dfm->field->tag, songalbumid);
|
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_DAAP, "Generated meta tag %s (%" PRIi64 ") based on (%s,%s)\n", dfm->field->desc, songalbumid, dbmfi.album_artist, dbmfi.album);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
val = 0;
|
val = 0;
|
||||||
|
|
||||||
if (transcode)
|
if (transcode)
|
||||||
|
Loading…
Reference in New Issue
Block a user