Bug 1727783 - Add tables for session metadata storage to places DB. r=mak

Differential Revision: https://phabricator.services.mozilla.com/D123780
This commit is contained in:
Mark Banner 2021-09-07 14:32:07 +00:00
Родитель bbe656b884
Коммит 59ca6c09a9
8 изменённых файлов: 59 добавлений и 5 удалений

Просмотреть файл

@ -487,7 +487,7 @@ const startupPhases = {
stat: 4,
fsync: 3,
read: 44,
write: 164,
write: 170,
},
{
// bug 1391590
@ -503,7 +503,7 @@ const startupPhases = {
fsync: 2,
read: 4,
stat: 3,
write: 1317,
write: 1320,
},
{
// bug 1391590

Просмотреть файл

@ -1203,6 +1203,13 @@ nsresult Database::InitSchema(bool* aDatabaseMigrated) {
// Firefox 92 uses schema version 58
if (currentSchemaVersion < 59) {
rv = MigrateV59Up();
NS_ENSURE_SUCCESS(rv, rv);
}
// Firefox 94 uses schema version 59
// Schema Upgrades must add migration code here.
// >>> IMPORTANT! <<<
// NEVER MIX UP SYNC AND ASYNC EXECUTION IN MIGRATORS, YOU MAY LOCK THE
@ -1321,6 +1328,14 @@ nsresult Database::InitSchema(bool* aDatabaseMigrated) {
CREATE_MOZ_PLACES_METADATA_GROUPS_TO_SNAPSHOTS);
NS_ENSURE_SUCCESS(rv, rv);
// moz_session_metadata
rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_SESSION_METADATA);
NS_ENSURE_SUCCESS(rv, rv);
// moz_session_to_places
rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_SESSION_TO_PLACES);
NS_ENSURE_SUCCESS(rv, rv);
// The bookmarks roots get initialized in CheckRoots().
}
@ -2281,6 +2296,20 @@ nsresult Database::MigrateV58Up() {
return NS_OK;
}
nsresult Database::MigrateV59Up() {
// Add metadata snapshots tables if necessary.
nsCOMPtr<mozIStorageStatement> stmt;
nsresult rv = mMainConn->CreateStatement(
"SELECT id FROM moz_session_metadata"_ns, getter_AddRefs(stmt));
if (NS_FAILED(rv)) {
rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_SESSION_METADATA);
NS_ENSURE_SUCCESS(rv, rv);
rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_SESSION_TO_PLACES);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
nsresult Database::ConvertOldStyleQuery(nsCString& aURL) {
AutoTArray<QueryKeyValuePair, 8> tokens;
nsresult rv = TokenizeQueryString(aURL, &tokens);

Просмотреть файл

@ -18,7 +18,7 @@
// This is the schema version. Update it at any schema change and add a
// corresponding migrateVxx method below.
#define DATABASE_SCHEMA_VERSION 58
#define DATABASE_SCHEMA_VERSION 59
// Fired after Places inited.
#define TOPIC_PLACES_INIT_COMPLETE "places-init-complete"
@ -331,6 +331,7 @@ class Database final : public nsIObserver, public nsSupportsWeakReference {
nsresult MigrateV56Up();
nsresult MigrateV57Up();
nsresult MigrateV58Up();
nsresult MigrateV59Up();
void MigrateV52OriginFrecencies();

Просмотреть файл

@ -348,4 +348,26 @@
" moz_places_metadata_snapshots(place_id) ON DELETE CASCADE " \
") WITHOUT ROWID")
#define CREATE_MOZ_SESSION_METADATA \
nsLiteralCString( \
"CREATE TABLE IF NOT EXISTS moz_session_metadata ( " \
" id INTEGER PRIMARY KEY, " \
" guid TEXT NOT NULL UNIQUE, " \
" last_saved_at INTEGER NOT NULL DEFAULT 0, " \
" data TEXT " \
")")
#define CREATE_MOZ_SESSION_TO_PLACES \
nsLiteralCString( \
"CREATE TABLE IF NOT EXISTS moz_session_to_places ( " \
" session_id INTEGER NOT NULL, " \
" place_id INTEGER NOT NULL , " \
" position INTEGER, " \
" PRIMARY KEY (session_id, place_id), " \
" FOREIGN KEY (place_id) REFERENCES moz_places(id) ON DELETE " \
"CASCADE " \
" FOREIGN KEY (session_id) REFERENCES moz_session_metadata(id) ON " \
"DELETE CASCADE " \
") WITHOUT ROWID")
#endif // __nsPlacesTables_h__

Просмотреть файл

@ -15,7 +15,7 @@ var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
// Put any other stuff relative to this test folder below.
const CURRENT_SCHEMA_VERSION = 58;
const CURRENT_SCHEMA_VERSION = 59;
const FIRST_UPGRADABLE_SCHEMA_VERSION = 43;
async function assertAnnotationsRemoved(db, expectedAnnos) {

Просмотреть файл

@ -21,6 +21,8 @@ add_task(async function database_is_valid() {
"moz_places_metadata_snapshots_extra",
"moz_places_metadata_snapshots_groups",
"moz_places_metadata_groups_to_snapshots",
"moz_session_metadata",
"moz_session_to_places",
]) {
let count = (
await db.execute(`SELECT count(*) FROM ${table}`)

Просмотреть файл

@ -6,7 +6,7 @@ support-files =
places_outdated.sqlite
places_v43.sqlite
places_v54.sqlite
places_v58.sqlite
places_v59.sqlite
[test_current_from_downgraded.js]
[test_current_from_outdated.js]