mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 23:25:56 -05:00
[db] Add function to cleanup the 'groups' table (artists and albums)
Allows removing of item no longer referenced from the files table
This commit is contained in:
parent
1ab9151489
commit
3d3c27190b
38
src/db.c
38
src/db.c
@ -3385,6 +3385,44 @@ db_groups_clear(void)
|
||||
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
|
||||
db_group_type_bypersistentid(int64_t persistentid)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user