Bug 1748509 - Add builder fields to snapshot groups and more indices. r=mak

Differential Revision: https://phabricator.services.mozilla.com/D135122
This commit is contained in:
Mark Banner 2022-01-11 14:32:52 +00:00
parent c4c6925914
commit 522af762cb
9 changed files with 114 additions and 7 deletions

View File

@ -473,8 +473,8 @@ const startupPhases = {
ignoreIfUnused: true,
stat: 4,
fsync: 3,
read: 48,
write: 172,
read: 51,
write: 178,
},
{
// bug 1391590
@ -490,7 +490,7 @@ const startupPhases = {
fsync: 2,
read: 4,
stat: 3,
write: 1321,
write: 1324,
},
{
// bug 1391590

View File

@ -1225,7 +1225,12 @@ nsresult Database::InitSchema(bool* aDatabaseMigrated) {
NS_ENSURE_SUCCESS(rv, rv);
}
// Firefox 97 uses schema version 61
if (currentSchemaVersion < 62) {
rv = MigrateV62Up();
NS_ENSURE_SUCCESS(rv, rv);
}
// Firefox 97 uses schema version 62
// Schema Upgrades must add migration code here.
// >>> IMPORTANT! <<<
@ -1322,6 +1327,8 @@ nsresult Database::InitSchema(bool* aDatabaseMigrated) {
rv = mMainConn->ExecuteSimpleSQL(
CREATE_IDX_MOZ_PLACES_METADATA_PLACECREATED);
NS_ENSURE_SUCCESS(rv, rv);
rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_METADATA_REFERRER);
NS_ENSURE_SUCCESS(rv, rv);
// moz_places_metadata_search_queries
rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_METADATA_SEARCH_QUERIES);
@ -1330,11 +1337,17 @@ nsresult Database::InitSchema(bool* aDatabaseMigrated) {
// moz_places_metadata_snapshots
rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_METADATA_SNAPSHOTS);
NS_ENSURE_SUCCESS(rv, rv);
rv = mMainConn->ExecuteSimpleSQL(
CREATE_IDX_MOZ_PLACES_METADATA_SNAPSHOTS_PINNNED);
NS_ENSURE_SUCCESS(rv, rv);
// moz_places_metadata_snapshots_extra
rv =
mMainConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_METADATA_SNAPSHOTS_EXTRA);
NS_ENSURE_SUCCESS(rv, rv);
rv = mMainConn->ExecuteSimpleSQL(
CREATE_IDX_MOZ_PLACES_METADATA_SNAPSHOTS_EXTRA_TYPE);
NS_ENSURE_SUCCESS(rv, rv);
// moz_places_metadata_snapshots_groups
rv = mMainConn->ExecuteSimpleSQL(
@ -2366,6 +2379,36 @@ nsresult Database::MigrateV61Up() {
return NS_OK;
}
nsresult Database::MigrateV62Up() {
// Add builder columns if necessary.
nsCOMPtr<mozIStorageStatement> stmt;
nsresult rv = mMainConn->CreateStatement(
"SELECT builder FROM moz_places_metadata_snapshots_groups"_ns,
getter_AddRefs(stmt));
if (NS_FAILED(rv)) {
rv = mMainConn->ExecuteSimpleSQL(
"ALTER TABLE moz_places_metadata_snapshots_groups "
"ADD COLUMN builder TEXT NOT NULL "_ns);
NS_ENSURE_SUCCESS(rv, rv);
rv = mMainConn->ExecuteSimpleSQL(
"ALTER TABLE moz_places_metadata_snapshots_groups "
"ADD COLUMN builder_data TEXT "_ns);
NS_ENSURE_SUCCESS(rv, rv);
}
// Add indexes if necessary.
rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_METADATA_REFERRER);
NS_ENSURE_SUCCESS(rv, rv);
rv = mMainConn->ExecuteSimpleSQL(
CREATE_IDX_MOZ_PLACES_METADATA_SNAPSHOTS_PINNNED);
NS_ENSURE_SUCCESS(rv, rv);
rv = mMainConn->ExecuteSimpleSQL(
CREATE_IDX_MOZ_PLACES_METADATA_SNAPSHOTS_EXTRA_TYPE);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
nsresult Database::ConvertOldStyleQuery(nsCString& aURL) {
AutoTArray<QueryKeyValuePair, 8> tokens;
nsresult rv = TokenizeQueryString(aURL, &tokens);

View File

@ -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 61
#define DATABASE_SCHEMA_VERSION 62
// Fired after Places inited.
#define TOPIC_PLACES_INIT_COMPLETE "places-init-complete"
@ -334,6 +334,7 @@ class Database final : public nsIObserver, public nsSupportsWeakReference {
nsresult MigrateV59Up();
nsresult MigrateV60Up();
nsresult MigrateV61Up();
nsresult MigrateV62Up();
void MigrateV52OriginFrecencies();

View File

@ -108,4 +108,18 @@
CREATE_PLACES_IDX("placecreated_uniqueindex", "moz_places_metadata", \
"place_id, created_at", "UNIQUE")
#define CREATE_IDX_MOZ_PLACES_METADATA_REFERRER \
CREATE_PLACES_IDX("referrerindex", "moz_places_metadata", \
"referrer_place_id", "")
// moz_places_metadata_snapshots
#define CREATE_IDX_MOZ_PLACES_METADATA_SNAPSHOTS_PINNNED \
CREATE_PLACES_IDX("pinnedindex", "moz_places_metadata_snapshots", \
"user_persisted, last_interaction_at", "")
// moz_places_metadata_snapshots_extra
#define CREATE_IDX_MOZ_PLACES_METADATA_SNAPSHOTS_EXTRA_TYPE \
CREATE_PLACES_IDX("typeindex", "moz_places_metadata_snapshots_extra", \
"type", "")
#endif // nsPlacesIndexes_h__

View File

@ -334,7 +334,9 @@
nsLiteralCString( \
"CREATE TABLE IF NOT EXISTS moz_places_metadata_snapshots_groups ( " \
" id INTEGER PRIMARY KEY, " \
" title TEXT NOT NULL " \
" title TEXT NOT NULL, " \
" builder TEXT NOT NULL, " \
" builder_data TEXT " \
")")
#define CREATE_MOZ_PLACES_METADATA_GROUPS_TO_SNAPSHOTS \

View File

@ -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 = 61;
const CURRENT_SCHEMA_VERSION = 62;
const FIRST_UPGRADABLE_SCHEMA_VERSION = 43;
async function assertAnnotationsRemoved(db, expectedAnnos) {

View File

@ -0,0 +1,45 @@
add_task(async function setup() {
await setupPlacesDatabase("places_v61.sqlite");
// Since this migration doesn't affect favicons.sqlite, we can reuse v41.
await setupPlacesDatabase("favicons_v41.sqlite", "favicons.sqlite");
});
add_task(async function database_is_valid() {
// Accessing the database for the first time triggers migration.
Assert.equal(
PlacesUtils.history.databaseStatus,
PlacesUtils.history.DATABASE_STATUS_UPGRADED
);
let db = await PlacesUtils.promiseDBConnection();
Assert.equal(await db.getSchemaVersion(), CURRENT_SCHEMA_VERSION);
});
add_task(async function builder_fields_in_database() {
let db = await PlacesUtils.promiseDBConnection();
await db.execute(
`SELECT builder, builder_data FROM moz_places_metadata_snapshots_groups`
);
});
add_task(async function indexes_in_database() {
let db = await PlacesUtils.promiseDBConnection();
let rows = await db.execute(
`SELECT * FROM sqlite_master WHERE type = "index"`
);
let indexes = rows.map(r => r.getResultByName("name"));
Assert.ok(
indexes.includes("moz_places_metadata_referrerindex"),
"Should contain the referrer index"
);
Assert.ok(
indexes.includes("moz_places_metadata_snapshots_pinnedindex"),
"Should contain the pinned index"
);
Assert.ok(
indexes.includes("moz_places_metadata_snapshots_extra_typeindex"),
"Should contain the type index"
);
});

View File

@ -7,6 +7,7 @@ support-files =
places_v43.sqlite
places_v54.sqlite
places_v61.sqlite
places_v62.sqlite
[test_current_from_downgraded.js]
[test_current_from_outdated.js]
@ -18,3 +19,4 @@ support-files =
[test_current_from_v50.js]
[test_current_from_v53.js]
[test_current_from_v54.js]
[test_current_from_v61.js]