From d799ec7ac9ac5f42b495faacfe592614e4b321db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Tue, 26 Mar 2024 19:19:44 +0100 Subject: [PATCH] Add skipping migration when previous attempt failed (#2508) --- .../wulkanowy/data/WulkanowySdkFactory.kt | 18 +++++++++++++++--- .../data/repositories/SemesterRepository.kt | 5 ++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/data/WulkanowySdkFactory.kt b/app/src/main/java/io/github/wulkanowy/data/WulkanowySdkFactory.kt index a4911f95a..cede6f920 100644 --- a/app/src/main/java/io/github/wulkanowy/data/WulkanowySdkFactory.kt +++ b/app/src/main/java/io/github/wulkanowy/data/WulkanowySdkFactory.kt @@ -23,6 +23,7 @@ class WulkanowySdkFactory @Inject constructor( ) { private val eduOneMutex = Mutex() + private val migrationFailedStudentIds = mutableSetOf() private val sdk = Sdk().apply { androidVersion = android.os.Build.VERSION.RELEASE @@ -78,14 +79,24 @@ class WulkanowySdkFactory @Inject constructor( private suspend fun checkEduOneAndMigrateIfNecessary(student: Student): Boolean { if (student.isEduOne != null) return student.isEduOne + if (student.id in migrationFailedStudentIds) { + Timber.i("Migration eduOne: skipping because of previous failure") + return false + } + eduOneMutex.withLock { + if (student.id in migrationFailedStudentIds) { + Timber.i("Migration eduOne: skipping because of previous failure") + return false + } + val studentFromDatabase = studentDb.loadById(student.id) if (studentFromDatabase?.isEduOne != null) { - Timber.d("Migration eduOne: already done") + Timber.i("Migration eduOne: already done") return studentFromDatabase.isEduOne } - Timber.d("Migration eduOne: flag missing. Running migration...") + Timber.i("Migration eduOne: flag missing. Running migration...") val initializedSdk = buildSdk( student = student, semester = null, @@ -96,7 +107,8 @@ class WulkanowySdkFactory @Inject constructor( .getOrNull() if (newCurrentStudent == null) { - Timber.d("Migration eduOne: failed, so skipping") + Timber.i("Migration eduOne: failed, so skipping") + migrationFailedStudentIds.add(student.id) return false } diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/SemesterRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/SemesterRepository.kt index e15f93099..ef7ae5950 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/SemesterRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/SemesterRepository.kt @@ -64,7 +64,10 @@ class SemesterRepository @Inject constructor( .getSemesters() .mapToEntities(student.studentId) - if (new.isEmpty()) return Timber.i("Empty semester list!") + if (new.isEmpty()) { + Timber.i("Empty semester list from SDK!") + return + } val old = semesterDb.loadAll(student) semesterDb.removeOldAndSaveNew(