From febc149ee04f43884d7918379285d74afddb239e Mon Sep 17 00:00:00 2001 From: "brettw%gmail.com" Date: Tue, 11 Apr 2006 17:37:13 +0000 Subject: [PATCH] Bug 331158 r=vladimir Add preload capability to storage service for sqlite pager cache. git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@194148 18797224-902f-48f8-a5cc-f745e15eee43 --- .../storage/public/mozIStorageConnection.idl | 19 ++++++++++++++++++- mozilla/storage/src/mozStorageConnection.cpp | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/mozilla/storage/public/mozIStorageConnection.idl b/mozilla/storage/public/mozIStorageConnection.idl index 30088b111b8..69e0c143ba7 100644 --- a/mozilla/storage/public/mozIStorageConnection.idl +++ b/mozilla/storage/public/mozIStorageConnection.idl @@ -21,6 +21,7 @@ * * Contributor(s): * Vladimir Vukicevic + * Brett Wilson * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -49,7 +50,7 @@ interface nsIFile; * creating prepared statements, executing SQL, and examining database * errors. */ -[scriptable, uuid(4c459c8a-f548-42b7-8d7e-42ea1aed3876)] +[scriptable, uuid(77015f88-bfc2-4669-b1c3-cc19fb07cd4e)] interface mozIStorageConnection : nsISupports { /* * Initialization and status @@ -192,4 +193,20 @@ interface mozIStorageConnection : nsISupports { void createFunction(in string aFunctionName, in long aNumArguments, in mozIStorageFunction aFunction); + + /** + * This is used to preload the database cache. It loads pages from the + * start of the database file until the memory cache (specified by + * "PRAGMA cache_size=") is full or the entire file is read. + * + * The cache MUST be active on the database for this to work. This means + * that you must have a transaction open on the connection, or have a + * transaction open on another connection that shares the same pager cache. + * This cached data will go away when the transaction is closed. + * + * This preload operation can dramatically speed up read operations because + * the data is loaded as one large block. Normally, pages are read in on + * demand, which can cause many disk seeks. + */ + void preload(); }; diff --git a/mozilla/storage/src/mozStorageConnection.cpp b/mozilla/storage/src/mozStorageConnection.cpp index 0fc1cdeb8a8..2dd37347420 100644 --- a/mozilla/storage/src/mozStorageConnection.cpp +++ b/mozilla/storage/src/mozStorageConnection.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Vladimir Vukicevic + * Brett Wilson * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -441,6 +442,19 @@ mozStorageConnection::CreateFunction(const char *aFunctionName, return NS_OK; } +/** + * Mozilla-specific sqlite function to preload the DB into the cache. See the + * IDL and sqlite3.h + */ +nsresult +mozStorageConnection::Preload() +{ + int srv = sqlite3Preload(mDBConn); + if (srv != SQLITE_OK) + return NS_ERROR_FAILURE; + return NS_OK; +} + /** ** Other bits **/