Skip onboarding migration if no migratable profiles (#1002)

Annoying!
This commit is contained in:
Davide 2024-12-11 22:20:14 +01:00 committed by GitHub
parent c6b3ad5921
commit 81aa3a2714
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 40 additions and 2 deletions

View File

@ -29,6 +29,9 @@ import SwiftUI
struct OnboardingModifier: ViewModifier { struct OnboardingModifier: ViewModifier {
@EnvironmentObject
private var migrationManager: MigrationManager
@Environment(\.isUITesting) @Environment(\.isUITesting)
private var isUITesting private var isUITesting
@ -87,6 +90,10 @@ private extension OnboardingModifier {
switch step { switch step {
case .migrateV3: case .migrateV3:
guard migrationManager.hasMigratableProfiles else {
advance()
return
}
modalRoute = .migrateProfiles modalRoute = .migrateProfiles
case .community: case .community:
isPresentingCommunity = true isPresentingCommunity = true

View File

@ -62,6 +62,10 @@ public final class MigrationManager: ObservableObject {
// MARK: - Public interface // MARK: - Public interface
extension MigrationManager { extension MigrationManager {
public var hasMigratableProfiles: Bool {
profileStrategy.hasMigratableProfiles
}
public func fetchMigratableProfiles() async throws -> [MigratableProfile] { public func fetchMigratableProfiles() async throws -> [MigratableProfile] {
try await profileStrategy.fetchMigratableProfiles() try await profileStrategy.fetchMigratableProfiles()
} }
@ -173,7 +177,8 @@ private extension MigrationManager {
// MARK: - Dummy // MARK: - Dummy
private final class DummyProfileStrategy: ProfileMigrationStrategy { private final class DummyProfileStrategy: ProfileMigrationStrategy {
public init() { var hasMigratableProfiles: Bool {
false
} }
public func fetchMigratableProfiles() async throws -> [MigratableProfile] { public func fetchMigratableProfiles() async throws -> [MigratableProfile] {

View File

@ -27,6 +27,8 @@ import Foundation
import PassepartoutKit import PassepartoutKit
public protocol ProfileMigrationStrategy { public protocol ProfileMigrationStrategy {
var hasMigratableProfiles: Bool { get}
func fetchMigratableProfiles() async throws -> [MigratableProfile] func fetchMigratableProfiles() async throws -> [MigratableProfile]
func fetchProfile(withId profileId: UUID) async throws -> Profile? func fetchProfile(withId profileId: UUID) async throws -> Profile?

View File

@ -42,6 +42,22 @@ final class CDProfileRepositoryV2: Sendable {
self.context = context self.context = context
} }
var hasMigratableProfiles: Bool {
do {
return try context.performAndWait { [weak self] in
guard let self else {
return false
}
let entities = try CDProfile.fetchRequest().execute()
return !entities.compactMap {
($0.encryptedJSON ?? $0.json) != nil
}.isEmpty
}
} catch {
return false
}
}
func migratableProfiles() async throws -> [MigratableProfile] { func migratableProfiles() async throws -> [MigratableProfile] {
try await fetchProfiles( try await fetchProfiles(
prefetch: { prefetch: {
@ -49,7 +65,7 @@ final class CDProfileRepositoryV2: Sendable {
}, },
map: { map: {
$0.compactMap { $0.compactMap {
guard $0.value.encryptedJSON ?? $0.value.json != nil else { guard ($0.value.encryptedJSON ?? $0.value.json) != nil else {
pp_log(.App.migration, .error, "ProfileV2 \($0.key) is not migratable: missing JSON") pp_log(.App.migration, .error, "ProfileV2 \($0.key) is not migratable: missing JSON")
return nil return nil
} }

View File

@ -74,6 +74,10 @@ public final class ProfileV2MigrationStrategy: ProfileMigrationStrategy, Sendabl
// MARK: - ProfileMigrationStrategy // MARK: - ProfileMigrationStrategy
extension ProfileV2MigrationStrategy { extension ProfileV2MigrationStrategy {
public var hasMigratableProfiles: Bool {
profilesRepository.hasMigratableProfiles
}
public func fetchMigratableProfiles() async throws -> [MigratableProfile] { public func fetchMigratableProfiles() async throws -> [MigratableProfile] {
try await profilesRepository.migratableProfiles() try await profilesRepository.migratableProfiles()
} }

View File

@ -34,6 +34,10 @@ final class MockProfileMigrationStrategy: ProfileMigrationStrategy {
var failedProfiles: Set<UUID> = [] var failedProfiles: Set<UUID> = []
var hasMigratableProfiles: Bool {
!migratedProfiles.isEmpty
}
func fetchMigratableProfiles() async throws -> [MigratableProfile] { func fetchMigratableProfiles() async throws -> [MigratableProfile] {
migratableProfiles migratableProfiles
} }