Bug 421482 - Firefox 3 uses fsync excessively. r=shaver, a=schrep

git-svn-id: svn://10.0.0.236/trunk@251782 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sdwilsh%shawnwilsher.com 2008-05-23 14:56:10 +00:00
parent e344ee65ad
commit bc0dbff7c8
2 changed files with 41 additions and 0 deletions

View File

@ -48,6 +48,8 @@
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsIVariant.h" #include "nsIVariant.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "mozIStorageAggregateFunction.h" #include "mozIStorageAggregateFunction.h"
#include "mozIStorageFunction.h" #include "mozIStorageFunction.h"
@ -66,6 +68,8 @@
PRLogModuleInfo* gStorageLog = nsnull; PRLogModuleInfo* gStorageLog = nsnull;
#endif #endif
#define PREF_TS_SYNCHRONOUS "toolkit.storage.synchronous"
NS_IMPL_ISUPPORTS1(mozStorageConnection, mozIStorageConnection) NS_IMPL_ISUPPORTS1(mozStorageConnection, mozIStorageConnection)
mozStorageConnection::mozStorageConnection(mozIStorageService* aService) mozStorageConnection::mozStorageConnection(mozIStorageService* aService)
@ -157,6 +161,28 @@ mozStorageConnection::Initialize(nsIFile *aDatabaseFile)
return ConvertResultCode(srv); return ConvertResultCode(srv);
} }
// Set the synchronous PRAGMA, according to the pref
nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID));
PRInt32 synchronous = 1; // Default to NORMAL if pref not set
if (pref)
(void)pref->GetIntPref(PREF_TS_SYNCHRONOUS, &synchronous);
switch (synchronous) {
case 2:
(void)ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"PRAGMA synchronous = FULL;"));
break;
case 0:
(void)ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"PRAGMA synchronous = OFF;"));
break;
case 1:
default:
(void)ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"PRAGMA synchronous = NORMAL;"));
break;
}
return NS_OK; return NS_OK;
} }

View File

@ -197,6 +197,20 @@ function test_createTable(){
} }
} }
function test_defaultSynchronousAtNormal()
{
var msc = getOpenedDatabase();
var stmt = createStatement("PRAGMA synchronous;");
try {
stmt.executeStep();
do_check_eq(1, stmt.getInt32(0));
}
finally {
stmt.reset();
stmt.finalize();
}
}
var tests = [ var tests = [
test_connectionReady_open, test_connectionReady_open,
test_connectionReady_closed, test_connectionReady_closed,
@ -216,6 +230,7 @@ var tests = [
test_set_schemaVersion_same, test_set_schemaVersion_same,
test_set_schemaVersion_negative, test_set_schemaVersion_negative,
test_createTable, test_createTable,
test_defaultSynchronousAtNormal,
]; ];
function run_test() function run_test()