forked from firka/firka
fix: migrate lesson cache after cachekey fix
This commit is contained in:
@@ -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<void> _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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 = <Setting>[
|
||||
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<NotifyWakeupInterval> get notifyWakeupInterval => SilentlySettable(this, SettingsRegistry.notifyWakeupInterval);
|
||||
SilentlySettable<bool> get fcmDebugNotifyOnMessage => SilentlySettable(this, SettingsRegistry.fcmDebugNotifyOnMessage);
|
||||
SilentlySettable<NotificationDeliveryMethod> get notificationDeliveryMethod => SilentlySettable(this, SettingsRegistry.notificationDeliveryMethod);
|
||||
SilentlySettable<bool> get lessonCacheKeyMigrationDone => SilentlySettable(this, SettingsRegistry.lessonCacheKeyMigrationDone);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user