Bug 1488776 - Move the urlbar connection to PlacesUtils. r=adw

Differential Revision: https://phabricator.services.mozilla.com/D5045

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Marco Bonardo 2018-09-05 23:42:05 +00:00
parent 7d48aaf18e
commit d21efaaa9b
2 changed files with 27 additions and 17 deletions

View File

@ -1431,6 +1431,13 @@ var PlacesUtils = {
*/
promiseDBConnection: () => gAsyncDBConnPromised,
/**
* This is pretty much the same as promiseDBConnection, but with a larger
* page cache, useful for consumers doing large table scans, like the urlbar.
* @see promiseDBConnection
*/
promiseLargeCacheDBConnection: () => gAsyncDBLargeCacheConnPromised,
/**
* Performs a read/write operation on the Places database through a Sqlite.jsm
* wrapped connection to the Places database.
@ -1939,6 +1946,22 @@ XPCOMUtils.defineLazyGetter(this, "gAsyncDBWrapperPromised",
}).catch(Cu.reportError)
);
XPCOMUtils.defineLazyGetter(this, "gAsyncDBLargeCacheConnPromised",
() => Sqlite.cloneStorageConnection({
connection: PlacesUtils.history.DBConnection,
readOnly: true,
}).then(async conn => {
setupDbForShutdown(conn, "PlacesUtils large cache read-only connection");
// Components like the urlbar often fallback to a table scan due to lack
// of full text indices. A larger cache helps reducing IO and improves
// performance. This value is expected to be larger than the default
// mozStorage value defined as MAX_CACHE_SIZE_BYTES in
// storage/mozStorageConnection.cpp.
await conn.execute("PRAGMA cache_size = -6144"); // 6MiB
return conn;
}).catch(Cu.reportError)
);
/**
* The metadata API allows consumers to store simple key-value metadata in
* Places. Keys are strings, values can be any type that SQLite supports:

View File

@ -2593,35 +2593,22 @@ UnifiedComplete.prototype = {
getDatabaseHandle() {
if (Prefs.get("autocomplete.enabled") && !this._promiseDatabase) {
this._promiseDatabase = (async () => {
let conn = await Sqlite.cloneStorageConnection({
connection: PlacesUtils.history.DBConnection,
readOnly: true,
});
let conn = await PlacesUtils.promiseLargeCacheDBConnection();
try {
Sqlite.shutdown.addBlocker("Places UnifiedComplete.js clone closing",
async () => {
Sqlite.shutdown.addBlocker("Places UnifiedComplete.js closing",
() => {
// Break a possible cycle through the
// previous result, the controller and
// ourselves.
this._currentSearch = null;
SwitchToTabStorage.shutdown();
await conn.close();
});
} catch (ex) {
// It's too late to block shutdown, just close the connection.
await conn.close();
// It's too late to block shutdown.
throw ex;
}
// Autocomplete often fallbacks to a table scan due to lack of text
// indices. A larger cache helps reducing IO and improving performance.
// The value used here is larger than the default Storage value defined
// as MAX_CACHE_SIZE_BYTES in storage/mozStorageConnection.cpp.
await conn.execute("PRAGMA cache_size = -6144"); // 6MiB
await SwitchToTabStorage.initDatabase(conn);
return conn;
})().catch(ex => {
dump("Couldn't get database handle: " + ex + "\n");