From 5a27c4e572667598b5c1d4b5cd6febdc719b2405 Mon Sep 17 00:00:00 2001 From: "deanm@chromium.org" Date: Wed, 5 Nov 2008 22:44:47 +0000 Subject: Actually preload the cookie database. The previous logic was inverted. Review URL: http://codereview.chromium.org/9183 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4830 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/common/net/cookie_monster_sqlite.cc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'chrome/common/net/cookie_monster_sqlite.cc') diff --git a/chrome/common/net/cookie_monster_sqlite.cc b/chrome/common/net/cookie_monster_sqlite.cc index 11bb002..0cb49ca 100644 --- a/chrome/common/net/cookie_monster_sqlite.cc +++ b/chrome/common/net/cookie_monster_sqlite.cc @@ -303,6 +303,19 @@ bool InitTable(sqlite3* db) { return true; } +void PrimeCache(sqlite3* db) { + // A statement must be open for the preload command to work. If the meta + // table can't be read, it probably means this is a new database and there + // is nothing to preload (so it's OK we do nothing). + SQLStatement dummy; + if (dummy.prepare(db, "SELECT * from meta") != SQLITE_OK) + return; + if (dummy.step() != SQLITE_ROW) + return; + + sqlite3Preload(db); +} + } // namespace bool SQLitePersistentCookieStore::Load( @@ -320,6 +333,8 @@ bool SQLitePersistentCookieStore::Load( return false; } + PrimeCache(db); + // Slurp all the cookies into the out-vector. SQLStatement smt; if (smt.prepare(db, @@ -330,17 +345,6 @@ bool SQLitePersistentCookieStore::Load( return false; } - // Step the statement and do the preload operation. Preload() requires that a - // statement be open on the database, so we oblige. We don't bother keeping - // this and reset the statement so we can read all the rows. - // - // The Preload call makes the read faster, since we will be reading most of - // the database, it's better to read it in one chunk than have a lot of seeks - // bringing it in organically. - if (smt.step() != SQLITE_ROW) - sqlite3Preload(db); - smt.reset(); - while (smt.step() == SQLITE_ROW) { std::string key = smt.column_string(1); scoped_ptr cc( -- cgit v1.1