mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-03 09:56:00 -05:00
Add defensive index creation on startup, fix indexes for ordered query (and update schema), better startup after interrupted shutdown
This commit is contained in:
parent
e54a8a1d9e
commit
90a6a39ce1
@ -65,7 +65,7 @@ static char *db_sqlite2_enum_query;
|
||||
|
||||
static char db_sqlite2_path[PATH_MAX + 1];
|
||||
|
||||
#define DB_SQLITE2_VERSION 10
|
||||
#define DB_SQLITE2_VERSION 11
|
||||
|
||||
|
||||
/* Forwards */
|
||||
@ -322,6 +322,14 @@ int db_sqlite2_event(int event_type) {
|
||||
|
||||
case DB_SQL_EVENT_STARTUP: /* this is a startup with existing songs */
|
||||
db_sqlite2_exec(NULL,E_FATAL,"vacuum");
|
||||
/* make sure our indexes exist */
|
||||
db_sqlite2_exec(NULL,E_DBG,"create index idx_path on "
|
||||
"songs(path,idx)");
|
||||
db_sqlite2_exec(NULL,E_DBG,"create index idx_songid on "
|
||||
"playlistitems(songid)");
|
||||
db_sqlite2_exec(NULL,E_DBG,"create index idx_playlistid on "
|
||||
"playlistitems(playlistid,songid)");
|
||||
|
||||
db_sqlite2_reload=0;
|
||||
break;
|
||||
|
||||
@ -374,7 +382,7 @@ int db_sqlite2_event(int event_type) {
|
||||
db_sqlite2_exec(NULL,E_FATAL,"end transaction");
|
||||
db_sqlite2_exec(NULL,E_FATAL,"pragma synchronous=normal");
|
||||
db_sqlite2_exec(NULL,E_FATAL,"create index idx_songid on playlistitems(songid)");
|
||||
db_sqlite2_exec(NULL,E_FATAL,"create index idx_playlistid on playlistitems(playlistid)");
|
||||
db_sqlite2_exec(NULL,E_FATAL,"create index idx_playlistid on playlistitems(playlistid,songid)");
|
||||
|
||||
} else {
|
||||
db_sqlite2_exec(NULL,E_FATAL,"delete from songs where id not in (select id from updated)");
|
||||
@ -465,7 +473,7 @@ char *db_sqlite2_initial1 =
|
||||
" subterm VARCHAR(255) DEFAULT NULL,\n"
|
||||
" value VARCHAR(1024) NOT NULL\n"
|
||||
");\n"
|
||||
"insert into config values ('version','','10');\n";
|
||||
"insert into config values ('version','','11');\n";
|
||||
|
||||
char *db_sqlite2_initial2 =
|
||||
"create table playlists (\n"
|
||||
|
@ -67,7 +67,7 @@ static char **db_sqlite3_row = NULL;
|
||||
|
||||
static char db_sqlite3_path[PATH_MAX + 1];
|
||||
|
||||
#define DB_SQLITE3_VERSION 10
|
||||
#define DB_SQLITE3_VERSION 11
|
||||
|
||||
|
||||
/* Forwards */
|
||||
@ -357,6 +357,12 @@ int db_sqlite3_event(int event_type) {
|
||||
|
||||
case DB_SQL_EVENT_STARTUP: /* this is a startup with existing songs */
|
||||
db_sqlite3_exec(NULL,E_FATAL,"vacuum");
|
||||
db_sqlite3_exec(NULL,E_DBG,"create index idx_path on "
|
||||
"songs(path,idx)");
|
||||
db_sqlite3_exec(NULL,E_DBG,"create index idx_songid on "
|
||||
"playlistitems(songid)");
|
||||
db_sqlite3_exec(NULL,E_DBG,"create index idx_playlistid on "
|
||||
"playlistitems(playlistid,songid)");
|
||||
db_sqlite3_reload=0;
|
||||
break;
|
||||
|
||||
@ -408,7 +414,7 @@ int db_sqlite3_event(int event_type) {
|
||||
db_sqlite3_exec(NULL,E_FATAL,"end transaction");
|
||||
db_sqlite3_exec(NULL,E_FATAL,"pragma synchronous=normal");
|
||||
db_sqlite3_exec(NULL,E_FATAL,"create index idx_songid on playlistitems(songid)");
|
||||
db_sqlite3_exec(NULL,E_FATAL,"create index idx_playlistid on playlistitems(playlistid)");
|
||||
db_sqlite3_exec(NULL,E_FATAL,"create index idx_playlistid on playlistitems(playlistid,songid)");
|
||||
|
||||
} else {
|
||||
db_sqlite3_exec(NULL,E_FATAL,"delete from songs where id not in (select id from updated)");
|
||||
@ -506,7 +512,7 @@ char *db_sqlite3_initial1 =
|
||||
" subterm VARCHAR(255) DEFAULT NULL,\n"
|
||||
" value VARCHAR(1024) NOT NULL\n"
|
||||
");\n"
|
||||
"insert into config values ('version','','10');\n";
|
||||
"insert into config values ('version','','11');\n";
|
||||
|
||||
char *db_sqlite3_initial2 =
|
||||
"create table playlists (\n"
|
||||
|
@ -242,8 +242,8 @@ char *db_sqlite_updates[] = {
|
||||
"update config set value=7 where term='version';\n",
|
||||
|
||||
/* version 7 -> version 8 */
|
||||
"create index idx_songid on playlistitems(songid);\n"
|
||||
"create index idx_playlistid on playlistitems(playlistid);\n"
|
||||
"create index idx_songid on playlistitems(songid)\n"
|
||||
"create index idx_playlistid on playlistitems(playlistid)\n"
|
||||
"update config set value=8 where term='version';\n",
|
||||
|
||||
/* version 8 -> version 9 */
|
||||
@ -354,5 +354,9 @@ char *db_sqlite_updates[] = {
|
||||
"create index idx_path on songs(path,idx);\n"
|
||||
"drop table tempsongs;\n"
|
||||
"update config set value=10 where term='version';\n",
|
||||
/* version 10 -> version 11 */
|
||||
"drop index idx_playlistid;\n"
|
||||
"create index idx_playlistid on playlistitems(playlistid,songid);\n"
|
||||
"update config set value=11 where term='version';\n",
|
||||
NULL /* No more versions! */
|
||||
};
|
||||
|
@ -222,8 +222,9 @@ void scan_process_playlistlist(void) {
|
||||
|
||||
if(strcasecmp(file,"iTunes Music Library.xml") == 0) {
|
||||
if(conf_get_int("scanning","process_xml",1)) {
|
||||
DPRINTF(E_LOG,L_SCAN,"Scanning %s\n",pnext->path);
|
||||
DPRINTF(E_INF,L_SCAN,"Scanning %s\n",pnext->path);
|
||||
scan_xml_playlist(pnext->path);
|
||||
DPRINTF(E_INF,L_SCAN,"Done Scanning %s\n",pnext->path);
|
||||
}
|
||||
} else if(strcasecmp(ext,".m3u") == 0) {
|
||||
scan_static_playlist(pnext->path);
|
||||
@ -263,16 +264,16 @@ int scan_init(char **patharray) {
|
||||
|
||||
scan_playlistlist.next=NULL;
|
||||
|
||||
while((patharray[index] != NULL) && (!config.stop)) {
|
||||
while((patharray[index] != NULL) && (!util_must_exit())) {
|
||||
DPRINTF(E_DBG,L_SCAN,"Scanning for MP3s in %s\n",patharray[index]);
|
||||
err=scan_path(patharray[index]);
|
||||
index++;
|
||||
}
|
||||
|
||||
if(db_end_song_scan())
|
||||
if(util_must_exit() || db_end_song_scan())
|
||||
return -1;
|
||||
|
||||
if(!config.stop) {
|
||||
if(!util_must_exit()) {
|
||||
DPRINTF(E_DBG,L_SCAN,"Processing playlists\n");
|
||||
scan_process_playlistlist();
|
||||
}
|
||||
@ -335,7 +336,7 @@ int scan_path(char *path) {
|
||||
is_compdir=scan_is_compdir(path);
|
||||
|
||||
while(1) {
|
||||
if(config.stop) {
|
||||
if(util_must_exit()) {
|
||||
DPRINTF(E_WARN,L_SCAN,"Stop req. Aborting scan of %s.\n",path);
|
||||
closedir(current_dir);
|
||||
free(extensions);
|
||||
|
Loading…
x
Reference in New Issue
Block a user