* 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
}
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 :
* 1) read configuration file
* 2) read command line arguments
@ -687,13 +701,7 @@ main(int argc, char * * argv)
free(db_path);
new_db = 1;
}
if( sqlite3_open(DB_PATH "/files.db", &db) != SQLITE_OK )
{
DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to open sqlite database! Exiting...\n");
}
else
{
sqlite3_busy_timeout(db, 5000);
open_db();
if( !new_db )
{
updateID = sql_get_int_field(db, "SELECT UPDATE_ID from SETTINGS");
@ -711,8 +719,7 @@ main(int argc, char * * argv)
sqlite3_close(db);
unlink(DB_PATH "/files.db");
system("rm -rf " DB_PATH "/art_cache");
sqlite3_open(DB_PATH "/files.db", &db);
sqlite3_busy_timeout(db, 5000);
open_db();
if( CreateDatabase() != 0 )
{
DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to create sqlite database! Exiting...\n");
@ -721,8 +728,7 @@ main(int argc, char * * argv)
scanning = 1;
sqlite3_close(db);
scanner_pid = fork();
sqlite3_open(DB_PATH "/files.db", &db);
sqlite3_busy_timeout(db, 5000);
open_db();
if( !scanner_pid ) // child (scanner) process
{
start_scanner();
@ -738,7 +744,6 @@ main(int argc, char * * argv)
{
DPRINTF(E_FATAL, L_GENERAL, "ERROR: pthread_create() failed for start_inotify.\n");
}
}
sudp = OpenAndConfSSDPReceiveSocket(n_lan_addr, lan_addr);
if(sudp < 0)

View File

@ -546,11 +546,6 @@ CreateDatabase(void)
"64", "0", "Browse Folders",
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 ( "
"ID INTEGER PRIMARY KEY AUTOINCREMENT, "
"OBJECT_ID TEXT UNIQUE NOT NULL, "