* Set database pragma for optimal performance on every DB open.

This commit is contained in:
Justin Maggard 2009-11-17 19:13:00 +00:00
parent 99bd55c463
commit 1549254753
2 changed files with 47 additions and 47 deletions

View File

@ -197,6 +197,20 @@ getfriendlyname(char * buf, int len)
#endif #endif
} }
void
open_db(void)
{
if( sqlite3_open(DB_PATH "/files.db", &db) != SQLITE_OK )
{
DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to open sqlite database! Exiting...\n");
}
sqlite3_busy_timeout(db, 5000);
sql_exec(db, "pragma page_size = 4096");
sql_exec(db, "pragma journal_mode = OFF");
sql_exec(db, "pragma synchronous = OFF;");
sql_exec(db, "pragma default_cache_size = 8192;");
}
/* init phase : /* init phase :
* 1) read configuration file * 1) read configuration file
* 2) read command line arguments * 2) read command line arguments
@ -687,57 +701,48 @@ main(int argc, char * * argv)
free(db_path); free(db_path);
new_db = 1; new_db = 1;
} }
if( sqlite3_open(DB_PATH "/files.db", &db) != SQLITE_OK ) open_db();
if( !new_db )
{ {
DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to open sqlite database! Exiting...\n"); updateID = sql_get_int_field(db, "SELECT UPDATE_ID from SETTINGS");
} }
else if( sql_get_int_field(db, "pragma user_version") != DB_VERSION )
{ {
sqlite3_busy_timeout(db, 5000); if( new_db )
if( !new_db )
{ {
updateID = sql_get_int_field(db, "SELECT UPDATE_ID from SETTINGS"); DPRINTF(E_WARN, L_GENERAL, "Creating new database...\n");
} }
if( sql_get_int_field(db, "pragma user_version") != DB_VERSION ) else
{ {
if( new_db ) DPRINTF(E_WARN, L_GENERAL, "Database version mismatch; need to recreate...\n");
{ }
DPRINTF(E_WARN, L_GENERAL, "Creating new database...\n"); sqlite3_close(db);
} unlink(DB_PATH "/files.db");
else system("rm -rf " DB_PATH "/art_cache");
{ open_db();
DPRINTF(E_WARN, L_GENERAL, "Database version mismatch; need to recreate...\n"); if( CreateDatabase() != 0 )
} {
sqlite3_close(db); DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to create sqlite database! Exiting...\n");
unlink(DB_PATH "/files.db"); }
system("rm -rf " DB_PATH "/art_cache");
sqlite3_open(DB_PATH "/files.db", &db);
sqlite3_busy_timeout(db, 5000);
if( CreateDatabase() != 0 )
{
DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to create sqlite database! Exiting...\n");
}
#if USE_FORK #if USE_FORK
scanning = 1; scanning = 1;
sqlite3_close(db); sqlite3_close(db);
scanner_pid = fork(); scanner_pid = fork();
sqlite3_open(DB_PATH "/files.db", &db); open_db();
sqlite3_busy_timeout(db, 5000); if( !scanner_pid ) // child (scanner) process
if( !scanner_pid ) // child (scanner) process
{
start_scanner();
sqlite3_close(db);
exit(EXIT_SUCCESS);
}
#else
start_scanner();
#endif
}
if( sqlite3_threadsafe() && sqlite3_libversion_number() >= 3005001 &&
GETFLAG(INOTIFY_MASK) && pthread_create(&inotify_thread, NULL, start_inotify, NULL) )
{ {
DPRINTF(E_FATAL, L_GENERAL, "ERROR: pthread_create() failed for start_inotify.\n"); start_scanner();
sqlite3_close(db);
exit(EXIT_SUCCESS);
} }
#else
start_scanner();
#endif
}
if( sqlite3_threadsafe() && sqlite3_libversion_number() >= 3005001 &&
GETFLAG(INOTIFY_MASK) && pthread_create(&inotify_thread, NULL, start_inotify, NULL) )
{
DPRINTF(E_FATAL, L_GENERAL, "ERROR: pthread_create() failed for start_inotify.\n");
} }
sudp = OpenAndConfSSDPReceiveSocket(n_lan_addr, lan_addr); sudp = OpenAndConfSSDPReceiveSocket(n_lan_addr, lan_addr);

View File

@ -546,11 +546,6 @@ CreateDatabase(void)
"64", "0", "Browse Folders", "64", "0", "Browse Folders",
0 }; 0 };
sql_exec(db, "pragma page_size = 4096");
sql_exec(db, "pragma journal_mode = OFF");
sql_exec(db, "pragma synchronous = OFF;");
sql_exec(db, "pragma default_cache_size = 8192;");
ret = sql_exec(db, "CREATE TABLE OBJECTS ( " ret = sql_exec(db, "CREATE TABLE OBJECTS ( "
"ID INTEGER PRIMARY KEY AUTOINCREMENT, " "ID INTEGER PRIMARY KEY AUTOINCREMENT, "
"OBJECT_ID TEXT UNIQUE NOT NULL, " "OBJECT_ID TEXT UNIQUE NOT NULL, "