mirror of
https://github.com/owntone/owntone-server.git
synced 2025-07-21 14:31:19 -04:00
Merge pull request #324 from chme/db3
Remove rebuilding the persistent-ids on startup
This commit is contained in:
commit
40d34ed4ad
50
src/db.c
50
src/db.c
@ -2024,18 +2024,6 @@ db_files_get_count_bymatch(char *path)
|
|||||||
#undef Q_TMPL
|
#undef Q_TMPL
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
db_files_update_songartistid(void)
|
|
||||||
{
|
|
||||||
db_query_run("UPDATE files SET songartistid = daap_songalbumid(LOWER(album_artist), '');", 0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
db_files_update_songalbumid(void)
|
|
||||||
{
|
|
||||||
db_query_run("UPDATE files SET songalbumid = daap_songalbumid(LOWER(album_artist), LOWER(album));", 0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
db_file_inc_playcount(int id)
|
db_file_inc_playcount(int id)
|
||||||
{
|
{
|
||||||
@ -3386,6 +3374,44 @@ db_groups_clear(void)
|
|||||||
return db_query_run("DELETE FROM groups;", 0, 1);
|
return db_query_run("DELETE FROM groups;", 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove album and artist entries in the groups table that are not longer referenced from the files table
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
db_groups_cleanup()
|
||||||
|
{
|
||||||
|
#define Q_TMPL_ALBUM "DELETE FROM groups WHERE type = 1 AND NOT persistentid IN (SELECT songalbumid from files WHERE disabled = 0);"
|
||||||
|
#define Q_TMPL_ARTIST "DELETE FROM groups WHERE type = 2 AND NOT persistentid IN (SELECT songartistid from files WHERE disabled = 0);"
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
db_transaction_begin();
|
||||||
|
|
||||||
|
ret = db_query_run(Q_TMPL_ALBUM, 0, 0);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
db_transaction_rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINTF(E_DBG, L_DB, "Removed album group-entries: %d\n", sqlite3_changes(hdl));
|
||||||
|
|
||||||
|
ret = db_query_run(Q_TMPL_ARTIST, 0, 0);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
db_transaction_rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINTF(E_DBG, L_DB, "Removed artist group-entries: %d\n", sqlite3_changes(hdl));
|
||||||
|
db_transaction_end();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#undef Q_TMPL_ALBUM
|
||||||
|
#undef Q_TMPL_ARTIST
|
||||||
|
}
|
||||||
|
|
||||||
static enum group_type
|
static enum group_type
|
||||||
db_group_type_bypersistentid(int64_t persistentid)
|
db_group_type_bypersistentid(int64_t persistentid)
|
||||||
{
|
{
|
||||||
|
9
src/db.h
9
src/db.h
@ -498,12 +498,6 @@ db_files_get_album_count(void);
|
|||||||
int
|
int
|
||||||
db_files_get_count_bymatch(char *path);
|
db_files_get_count_bymatch(char *path);
|
||||||
|
|
||||||
void
|
|
||||||
db_files_update_songartistid(void);
|
|
||||||
|
|
||||||
void
|
|
||||||
db_files_update_songalbumid(void);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
db_file_inc_playcount(int id);
|
db_file_inc_playcount(int id);
|
||||||
|
|
||||||
@ -617,6 +611,9 @@ db_pl_enable_bycookie(uint32_t cookie, char *path);
|
|||||||
int
|
int
|
||||||
db_groups_clear(void);
|
db_groups_clear(void);
|
||||||
|
|
||||||
|
int
|
||||||
|
db_groups_cleanup();
|
||||||
|
|
||||||
int
|
int
|
||||||
db_group_persistentid_byid(int id, int64_t *persistentid);
|
db_group_persistentid_byid(int id, int64_t *persistentid);
|
||||||
|
|
||||||
|
@ -1221,13 +1221,18 @@ bulk_scan(int flags)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
db_transaction_begin();
|
||||||
/* Protect spotify from the imminent purge if rescanning */
|
/* Protect spotify from the imminent purge if rescanning */
|
||||||
db_file_ping_bymatch("spotify:", 0);
|
db_file_ping_bymatch("spotify:", 0);
|
||||||
db_pl_ping_bymatch("spotify:", 0);
|
db_pl_ping_bymatch("spotify:", 0);
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_SCAN, "Purging old database content\n");
|
DPRINTF(E_DBG, L_SCAN, "Purging old database content\n");
|
||||||
db_purge_cruft(start);
|
db_purge_cruft(start);
|
||||||
|
db_groups_cleanup();
|
||||||
db_queue_cleanup();
|
db_queue_cleanup();
|
||||||
|
|
||||||
|
db_transaction_end();
|
||||||
|
|
||||||
cache_artwork_purge_cruft(start);
|
cache_artwork_purge_cruft(start);
|
||||||
|
|
||||||
DPRINTF(E_LOG, L_SCAN, "Bulk library scan completed in %.f sec\n", difftime(end, start));
|
DPRINTF(E_LOG, L_SCAN, "Bulk library scan completed in %.f sec\n", difftime(end, start));
|
||||||
@ -1278,14 +1283,6 @@ filescanner(void *arg)
|
|||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = db_groups_clear();
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_SCAN, "Error: could not clear old groups from DB\n");
|
|
||||||
|
|
||||||
pthread_exit(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only clear the queue if enabled (default) in config
|
// Only clear the queue if enabled (default) in config
|
||||||
clear_queue_on_stop_disabled = cfg_getbool(cfg_getsec(cfg, "mpd"), "clear_queue_on_stop_disable");
|
clear_queue_on_stop_disabled = cfg_getbool(cfg_getsec(cfg, "mpd"), "clear_queue_on_stop_disable");
|
||||||
if (!clear_queue_on_stop_disabled)
|
if (!clear_queue_on_stop_disabled)
|
||||||
@ -1299,13 +1296,6 @@ filescanner(void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Recompute all songartistids and songalbumids, in case the SQLite DB got transferred
|
|
||||||
* to a different host; the hash is not portable.
|
|
||||||
* It will also rebuild the groups we just cleared.
|
|
||||||
*/
|
|
||||||
db_files_update_songartistid();
|
|
||||||
db_files_update_songalbumid();
|
|
||||||
|
|
||||||
if (cfg_getbool(cfg_getsec(cfg, "library"), "filescan_disable"))
|
if (cfg_getbool(cfg_getsec(cfg, "library"), "filescan_disable"))
|
||||||
bulk_scan(F_SCAN_BULK | F_SCAN_FAST);
|
bulk_scan(F_SCAN_BULK | F_SCAN_FAST);
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user