mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-27 23:55:57 -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, 1, "dmap.itemid", "id" },
|
||||
{ 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, 1, "daap.songbitrate", "bitrate" },
|
||||
{ 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_episode_sort), 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
|
||||
@ -181,6 +182,7 @@ static ssize_t dbmfi_cols_map[] =
|
||||
dbmfi_offsetof(tv_network_name),
|
||||
dbmfi_offsetof(tv_episode_sort),
|
||||
dbmfi_offsetof(tv_season_num),
|
||||
dbmfi_offsetof(songalbumid),
|
||||
};
|
||||
|
||||
/* This list must be kept in sync with
|
||||
@ -719,7 +721,7 @@ db_build_query_groups(struct query_params *qp, char **q)
|
||||
char *idx;
|
||||
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)
|
||||
return -1;
|
||||
|
||||
@ -729,13 +731,13 @@ db_build_query_groups(struct query_params *qp, char **q)
|
||||
return -1;
|
||||
|
||||
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)
|
||||
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)
|
||||
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
|
||||
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)
|
||||
{
|
||||
@ -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," \
|
||||
" description, time_added, time_modified, time_played, db_timestamp, disabled, sample_count," \
|
||||
" 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," \
|
||||
" %Q, %Q, %Q, %Q, %d, %d, %d, %" PRIi64 ", %d, %d," \
|
||||
" %d, %d, %d, %d, %d, %d, %d, %d, %d," \
|
||||
" %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 *errmsg;
|
||||
int ret;
|
||||
@ -1539,7 +1542,8 @@ db_file_add(struct media_file_info *mfi)
|
||||
mfi->codectype, mfi->index, mfi->has_video,
|
||||
mfi->contentrating, mfi->bits_per_sample, mfi->album_artist,
|
||||
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)
|
||||
{
|
||||
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," \
|
||||
" bits_per_sample = %d, album_artist = %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;"
|
||||
char *query;
|
||||
char *errmsg;
|
||||
@ -1608,6 +1613,7 @@ db_file_update(struct media_file_info *mfi)
|
||||
mfi->bits_per_sample, mfi->album_artist,
|
||||
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->album_artist, mfi->album,
|
||||
mfi->id);
|
||||
|
||||
if (!query)
|
||||
@ -3151,7 +3157,8 @@ db_perthread_deinit(void)
|
||||
" tv_episode_num_str VARCHAR(1024) DEFAULT NULL," \
|
||||
" tv_network_name VARCHAR(1024) DEFAULT 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 \
|
||||
@ -3226,9 +3233,9 @@ db_perthread_deinit(void)
|
||||
*/
|
||||
|
||||
|
||||
#define SCHEMA_VERSION 6
|
||||
#define SCHEMA_VERSION 7
|
||||
#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 {
|
||||
char *query;
|
||||
|
3
src/db.h
3
src/db.h
@ -117,6 +117,8 @@ struct media_file_info {
|
||||
char *tv_network_name;
|
||||
|
||||
char *album_artist;
|
||||
|
||||
int64_t songalbumid;
|
||||
};
|
||||
|
||||
#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_episode_num_str;
|
||||
char *tv_network_name;
|
||||
char *songalbumid;
|
||||
};
|
||||
|
||||
#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 },
|
||||
{ 0, &dmap_asal,
|
||||
dbmfi_offsetof(album), -1, -1 },
|
||||
{ 0, &dmap_asai, /* special case; will be transformed to LONG (hash) */
|
||||
dbmfi_offsetof(album), -1, -1 },
|
||||
{ 0, &dmap_asai,
|
||||
dbmfi_offsetof(songalbumid), -1, -1 },
|
||||
{ 0, &dmap_asaa,
|
||||
dbmfi_offsetof(album_artist), -1, dbgri_offsetof(songalbumartist) },
|
||||
{ 0, &dmap_asar,
|
||||
@ -1305,7 +1305,6 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf,
|
||||
char **strval;
|
||||
char *ptr;
|
||||
uint32_t *meta;
|
||||
int64_t songalbumid;
|
||||
int nmeta;
|
||||
int nsongs;
|
||||
int transcode;
|
||||
@ -1486,19 +1485,6 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf,
|
||||
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;
|
||||
|
||||
if (transcode)
|
||||
|
Loading…
Reference in New Issue
Block a user