Merge remote-tracking branch 'origin/develop' into task/eric/replace_flatten_with_direct_parent

# Conflicts:
#	matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt
This commit is contained in:
ericdecanini 2022-07-19 11:17:14 +02:00
commit e926871570
10 changed files with 84 additions and 56 deletions

View file

@ -42,20 +42,13 @@ jobs:
column-name: "Need info"
label-name: "X-Needs-Info"
add_priority_design_issues_to_project:
name: P1 X-Needs-Design to Design project board
add_design_issues_to_project:
name: X-Needs-Design to Design project board
runs-on: ubuntu-latest
# Skip in forks
if: >
github.repository == 'vector-im/element-android' &&
contains(github.event.issue.labels.*.name, 'X-Needs-Design') &&
(contains(github.event.issue.labels.*.name, 'S-Critical') &&
(contains(github.event.issue.labels.*.name, 'O-Frequent') ||
contains(github.event.issue.labels.*.name, 'O-Occasional')) ||
contains(github.event.issue.labels.*.name, 'S-Major') &&
contains(github.event.issue.labels.*.name, 'O-Frequent') ||
contains(github.event.issue.labels.*.name, 'A11y') &&
contains(github.event.issue.labels.*.name, 'O-Frequent'))
contains(github.event.issue.labels.*.name, 'X-Needs-Design')
steps:
- uses: octokit/graphql-action@v2.x
id: add_to_project

1
changelog.d/6538.misc Normal file
View file

@ -0,0 +1 @@
Log durations of DB migration and migration steps.

View file

@ -13,7 +13,7 @@ ext.versions = [
def gradle = "7.1.3"
// Ref: https://kotlinlang.org/releases.html
def kotlin = "1.6.21"
def kotlinCoroutines = "1.6.3"
def kotlinCoroutines = "1.6.4"
def dagger = "2.42"
def retrofit = "2.9.0"
def arrow = "0.8.2"
@ -21,7 +21,7 @@ def markwon = "4.6.2"
def moshi = "1.13.0"
def lifecycle = "2.5.0"
def flowBinding = "1.2.0"
def flipper = "0.153.0"
def flipper = "0.154.0"
def epoxy = "4.6.2"
def mavericks = "2.7.0"
def glide = "4.13.2"

View file

@ -17,16 +17,18 @@
package org.matrix.android.sdk.internal.auth.db
import io.realm.DynamicRealm
import io.realm.RealmMigration
import org.matrix.android.sdk.internal.auth.db.migration.MigrateAuthTo001
import org.matrix.android.sdk.internal.auth.db.migration.MigrateAuthTo002
import org.matrix.android.sdk.internal.auth.db.migration.MigrateAuthTo003
import org.matrix.android.sdk.internal.auth.db.migration.MigrateAuthTo004
import org.matrix.android.sdk.internal.auth.db.migration.MigrateAuthTo005
import timber.log.Timber
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
import javax.inject.Inject
internal class AuthRealmMigration @Inject constructor() : RealmMigration {
internal class AuthRealmMigration @Inject constructor() : MatrixRealmMigration(
dbName = "Auth",
schemaVersion = 5L,
) {
/**
* Forces all AuthRealmMigration instances to be equal.
* Avoids Realm throwing when multiple instances of the migration are set.
@ -34,11 +36,7 @@ internal class AuthRealmMigration @Inject constructor() : RealmMigration {
override fun equals(other: Any?) = other is AuthRealmMigration
override fun hashCode() = 4000
val schemaVersion = 5L
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
Timber.d("Migrating Auth Realm from $oldVersion to $newVersion")
override fun doMigrate(realm: DynamicRealm, oldVersion: Long) {
if (oldVersion < 1) MigrateAuthTo001(realm).perform()
if (oldVersion < 2) MigrateAuthTo002(realm).perform()
if (oldVersion < 3) MigrateAuthTo003(realm).perform()

View file

@ -17,7 +17,6 @@
package org.matrix.android.sdk.internal.crypto.store.db
import io.realm.DynamicRealm
import io.realm.RealmMigration
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo001Legacy
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo002Legacy
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo003RiotX
@ -35,13 +34,22 @@ import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo015
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo016
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo017
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
import org.matrix.android.sdk.internal.util.time.Clock
import timber.log.Timber
import javax.inject.Inject
/**
* Schema version history:
* 0, 1, 2: legacy Riot-Android;
* 3: migrate to RiotX schema;
* 4, 5, 6, 7, 8, 9: migrations from RiotX (which was previously 1, 2, 3, 4, 5, 6).
*/
internal class RealmCryptoStoreMigration @Inject constructor(
private val clock: Clock,
) : RealmMigration {
) : MatrixRealmMigration(
dbName = "Crypto",
schemaVersion = 17L,
) {
/**
* Forces all RealmCryptoStoreMigration instances to be equal.
* Avoids Realm throwing when multiple instances of the migration are set.
@ -49,14 +57,7 @@ internal class RealmCryptoStoreMigration @Inject constructor(
override fun equals(other: Any?) = other is RealmCryptoStoreMigration
override fun hashCode() = 5000
// 0, 1, 2: legacy Riot-Android
// 3: migrate to RiotX schema
// 4, 5, 6, 7, 8, 9: migrations from RiotX (which was previously 1, 2, 3, 4, 5, 6)
val schemaVersion = 17L
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
Timber.d("Migrating Realm Crypto from $oldVersion to $newVersion")
override fun doMigrate(realm: DynamicRealm, oldVersion: Long) {
if (oldVersion < 1) MigrateCryptoTo001Legacy(realm).perform()
if (oldVersion < 2) MigrateCryptoTo002Legacy(realm).perform()
if (oldVersion < 3) MigrateCryptoTo003RiotX(realm).perform()

View file

@ -17,7 +17,6 @@
package org.matrix.android.sdk.internal.database
import io.realm.DynamicRealm
import io.realm.RealmMigration
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo001
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo002
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo003
@ -52,12 +51,15 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo031
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo032
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo033
import org.matrix.android.sdk.internal.util.Normalizer
import timber.log.Timber
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
import javax.inject.Inject
internal class RealmSessionStoreMigration @Inject constructor(
private val normalizer: Normalizer
) : RealmMigration {
) : MatrixRealmMigration(
dbName = "Session",
schemaVersion = 33L,
) {
/**
* Forces all RealmSessionStoreMigration instances to be equal.
* Avoids Realm throwing when multiple instances of the migration are set.
@ -65,11 +67,7 @@ internal class RealmSessionStoreMigration @Inject constructor(
override fun equals(other: Any?) = other is RealmSessionStoreMigration
override fun hashCode() = 1000
val schemaVersion = 33L
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
Timber.d("Migrating Realm Session from $oldVersion to $newVersion")
override fun doMigrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
if (oldVersion < 1) MigrateSessionTo001(realm).perform()
if (oldVersion < 2) MigrateSessionTo002(realm).perform()
if (oldVersion < 3) MigrateSessionTo003(realm).perform()

View file

@ -17,12 +17,14 @@
package org.matrix.android.sdk.internal.raw
import io.realm.DynamicRealm
import io.realm.RealmMigration
import org.matrix.android.sdk.internal.raw.migration.MigrateGlobalTo001
import timber.log.Timber
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
import javax.inject.Inject
internal class GlobalRealmMigration @Inject constructor() : RealmMigration {
internal class GlobalRealmMigration @Inject constructor() : MatrixRealmMigration(
dbName = "Global",
schemaVersion = 1L,
) {
/**
* Forces all GlobalRealmMigration instances to be equal.
* Avoids Realm throwing when multiple instances of the migration are set.
@ -30,11 +32,7 @@ internal class GlobalRealmMigration @Inject constructor() : RealmMigration {
override fun equals(other: Any?) = other is GlobalRealmMigration
override fun hashCode() = 2000
val schemaVersion = 1L
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
Timber.d("Migrating Global Realm from $oldVersion to $newVersion")
override fun doMigrate(realm: DynamicRealm, oldVersion: Long) {
if (oldVersion < 1) MigrateGlobalTo001(realm).perform()
}
}

View file

@ -17,12 +17,14 @@
package org.matrix.android.sdk.internal.session.identity.db
import io.realm.DynamicRealm
import io.realm.RealmMigration
import org.matrix.android.sdk.internal.session.identity.db.migration.MigrateIdentityTo001
import timber.log.Timber
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
import javax.inject.Inject
internal class RealmIdentityStoreMigration @Inject constructor() : RealmMigration {
internal class RealmIdentityStoreMigration @Inject constructor() : MatrixRealmMigration(
dbName = "Identity",
schemaVersion = 1L,
) {
/**
* Forces all RealmIdentityStoreMigration instances to be equal.
* Avoids Realm throwing when multiple instances of the migration are set.
@ -30,11 +32,7 @@ internal class RealmIdentityStoreMigration @Inject constructor() : RealmMigratio
override fun equals(other: Any?) = other is RealmIdentityStoreMigration
override fun hashCode() = 3000
val schemaVersion = 1L
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
Timber.d("Migrating Realm Identity from $oldVersion to $newVersion")
override fun doMigrate(realm: DynamicRealm, oldVersion: Long) {
if (oldVersion < 1) MigrateIdentityTo001(realm).perform()
}
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.util.database
import io.realm.DynamicRealm
import io.realm.RealmMigration
import timber.log.Timber
import kotlin.system.measureTimeMillis
internal abstract class MatrixRealmMigration(
private val dbName: String,
val schemaVersion: Long,
) : RealmMigration {
final override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
Timber.d("Migrating Realm $dbName from $oldVersion to $newVersion")
val duration = measureTimeMillis {
doMigrate(realm, oldVersion)
}
Timber.d("Migrating Realm $dbName from $oldVersion to $newVersion took $duration ms.")
}
abstract fun doMigrate(realm: DynamicRealm, oldVersion: Long)
}

View file

@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.util.database
import io.realm.DynamicRealm
import io.realm.RealmObjectSchema
import timber.log.Timber
import kotlin.system.measureTimeMillis
internal abstract class RealmMigrator(
private val realm: DynamicRealm,
@ -26,7 +27,10 @@ internal abstract class RealmMigrator(
) {
fun perform() {
Timber.d("Migrate ${realm.configuration.realmFileName} to $targetSchemaVersion")
doMigrate(realm)
val duration = measureTimeMillis {
doMigrate(realm)
}
Timber.d("Migrate ${realm.configuration.realmFileName} to $targetSchemaVersion took $duration ms.")
}
abstract fun doMigrate(realm: DynamicRealm)