From fdf350c2c6b08d05cd4cd98ed08f7a1a0019534f Mon Sep 17 00:00:00 2001 From: Armand <4831c0@proton.me> Date: Wed, 16 Sep 2026 14:29:31 +0200 Subject: [PATCH] fix: migrate lesson cache after cachekey fix --- firka/lib/app/initialization.dart | 15 +++++++++++++++ firka/lib/core/settings/settings_schema.dart | 5 +++++ firka/lib/core/settings/settings_schema.gen.dart | 4 +++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/firka/lib/app/initialization.dart b/firka/lib/app/initialization.dart index c418acff..74be61f8 100644 --- a/firka/lib/app/initialization.dart +++ b/firka/lib/app/initialization.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:io'; import 'dart:ui' as ui; import 'package:firka_common/data/database.dart'; +import 'package:firka_common/data/models/lesson_cache_model.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; @@ -120,6 +121,20 @@ void initTheme(AppInitialization data) { } Future _initData(AppInitialization init) async { await init.settings.loadAll(); + + // Old cacheKey scheme could collide across dates; wipe once so stale + // rows don't linger until their date range naturally resyncs. + if (!Settings.lessonCacheKeyMigrationDone.value) { + await isarInit.writeTxn(() async { + await isarInit.lessonCacheModels.clear(); + }); + await Settings.lessonCacheKeyMigrationDone.set(true); + logger.info( + "[Init] One-time migration: cleared the lesson cache to drop rows " + "keyed under the pre-fix cacheKey scheme", + ); + } + final selectedThemeId = Settings.selectedThemeId.value; final normalized = normalizeSelectedThemeId(selectedThemeId); if (normalized != selectedThemeId) { diff --git a/firka/lib/core/settings/settings_schema.dart b/firka/lib/core/settings/settings_schema.dart index fe755d6a..95011ca0 100644 --- a/firka/lib/core/settings/settings_schema.dart +++ b/firka/lib/core/settings/settings_schema.dart @@ -186,4 +186,9 @@ abstract class SettingsSchema { values: NotificationDeliveryMethod.values, ) NotificationDeliveryMethod get notificationDeliveryMethod; + + // Gates a one-time lesson cache wipe to drop rows keyed under the old, + // colliding cacheKey scheme (see LessonCacheModel.cacheKey history). + @BoolSetting(id: 1048, defaultValue: false) + bool get lessonCacheKeyMigrationDone; } diff --git a/firka/lib/core/settings/settings_schema.gen.dart b/firka/lib/core/settings/settings_schema.gen.dart index d2e97b61..e8210645 100644 --- a/firka/lib/core/settings/settings_schema.gen.dart +++ b/firka/lib/core/settings/settings_schema.gen.dart @@ -45,9 +45,10 @@ class SettingsRegistry { static const notifyWakeupInterval = EnumSetting(id: 1045, defaultValue: NotifyWakeupInterval.hourly, values: NotifyWakeupInterval.values); static const fcmDebugNotifyOnMessage = BoolSetting(id: 1046, defaultValue: false); static const notificationDeliveryMethod = EnumSetting(id: 1047, defaultValue: NotificationDeliveryMethod.auto, values: NotificationDeliveryMethod.values); + static const lessonCacheKeyMigrationDone = BoolSetting(id: 1048, defaultValue: false); static const all = [ - bellDelay, rounding1, rounding2, rounding3, rounding4, classAvgOnGraph, leftHandedMode, language, appIcon, childProtection, betaWarning, ttToastLessonNo, ttToastTestsAndHw, ttToastBreaks, statsForNerds, developerOptsEnabled, themeBrightness, ttToastSubstitution, ttToastABTimetable, wearOsSupport, titleFont, titleWeight, titleCapitalization, selectedThemeId, selectedCoreThemeId, selectedGradeThemeId, mockBackendEnabled, mockBackendUrl, lastSeen, surpriseGrades, seasonalAppIcons, uwuMode, notifyAll, notifyGrades, notifyHomeworkTests, notifyAbsences, notifyLessons, notifyMessages, notifyMutedSubjects, notifyWakeupInterval, fcmDebugNotifyOnMessage, notificationDeliveryMethod, + bellDelay, rounding1, rounding2, rounding3, rounding4, classAvgOnGraph, leftHandedMode, language, appIcon, childProtection, betaWarning, ttToastLessonNo, ttToastTestsAndHw, ttToastBreaks, statsForNerds, developerOptsEnabled, themeBrightness, ttToastSubstitution, ttToastABTimetable, wearOsSupport, titleFont, titleWeight, titleCapitalization, selectedThemeId, selectedCoreThemeId, selectedGradeThemeId, mockBackendEnabled, mockBackendUrl, lastSeen, surpriseGrades, seasonalAppIcons, uwuMode, notifyAll, notifyGrades, notifyHomeworkTests, notifyAbsences, notifyLessons, notifyMessages, notifyMutedSubjects, notifyWakeupInterval, fcmDebugNotifyOnMessage, notificationDeliveryMethod, lessonCacheKeyMigrationDone, ]; } @@ -94,4 +95,5 @@ extension SettingsAccessors on SettingsRepository { SilentlySettable get notifyWakeupInterval => SilentlySettable(this, SettingsRegistry.notifyWakeupInterval); SilentlySettable get fcmDebugNotifyOnMessage => SilentlySettable(this, SettingsRegistry.fcmDebugNotifyOnMessage); SilentlySettable get notificationDeliveryMethod => SilentlySettable(this, SettingsRegistry.notificationDeliveryMethod); + SilentlySettable get lessonCacheKeyMigrationDone => SilentlySettable(this, SettingsRegistry.lessonCacheKeyMigrationDone); }