From 90a6a39ce19a7b4611f2bff8669d9c3b7052fd91 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Sat, 29 Jul 2006 00:45:23 +0000 Subject: [PATCH] Add defensive index creation on startup, fix indexes for ordered query (and update schema), better startup after interrupted shutdown --- src/db-sql-sqlite2.c | 14 +++++++++++--- src/db-sql-sqlite3.c | 12 +++++++++--- src/db-sql-updates.c | 8 ++++++-- src/mp3-scanner.c | 11 ++++++----- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/db-sql-sqlite2.c b/src/db-sql-sqlite2.c index b61d1f35..0a974459 100644 --- a/src/db-sql-sqlite2.c +++ b/src/db-sql-sqlite2.c @@ -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" diff --git a/src/db-sql-sqlite3.c b/src/db-sql-sqlite3.c index 968022a8..a9a61563 100644 --- a/src/db-sql-sqlite3.c +++ b/src/db-sql-sqlite3.c @@ -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" diff --git a/src/db-sql-updates.c b/src/db-sql-updates.c index 8c7b2a2f..e6ad73f5 100644 --- a/src/db-sql-updates.c +++ b/src/db-sql-updates.c @@ -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! */ }; diff --git a/src/mp3-scanner.c b/src/mp3-scanner.c index f86946fb..f07c5cf1 100644 --- a/src/mp3-scanner.c +++ b/src/mp3-scanner.c @@ -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);