Skip to content

Commit 26491bb

Browse files
committed
Remove cache version handling from provider
This now happens as a database migration
1 parent 188dcdd commit 26491bb

File tree

3 files changed

+2
-33
lines changed

3 files changed

+2
-33
lines changed

lib/database/exercises/exercise_database.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class ExerciseDatabase extends _$ExerciseDatabase {
7373
// Named constructor for creating in-memory database
7474
ExerciseDatabase.inMemory(super.e);
7575

76+
/// Note that this needs to be bumped if the JSON response from the server changes
7677
@override
7778
int get schemaVersion => 1;
7879

lib/database/ingredients/ingredients_database.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class IngredientDatabase extends _$IngredientDatabase {
2626
// Named constructor for creating in-memory database
2727
IngredientDatabase.inMemory(super.e);
2828

29+
/// Note that this needs to be bumped if the JSON response from the server changes
2930
@override
3031
int get schemaVersion => 2;
3132

lib/providers/exercises.dart

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -362,41 +362,9 @@ class ExercisesProvider with ChangeNotifier {
362362
return exercise;
363363
}
364364

365-
/// Checks the required cache version
366-
///
367-
/// This is needed since the content of the exercise cache (the API response)
368-
/// can change and we need to invalidate it as a result
369-
Future<void> checkExerciseCacheVersion() async {
370-
final prefs = await SharedPreferences.getInstance();
371-
if (prefs.containsKey(PREFS_EXERCISE_CACHE_VERSION)) {
372-
final cacheVersion = prefs.getInt(PREFS_EXERCISE_CACHE_VERSION)!;
373-
374-
// Cache has has a different version, reset
375-
if (cacheVersion != CACHE_VERSION) {
376-
database.delete(database.exercises).go();
377-
}
378-
await prefs.setInt(PREFS_EXERCISE_CACHE_VERSION, CACHE_VERSION);
379-
380-
// Cache has no version key, reset
381-
// Note: this is only needed for very old apps that update and could probably
382-
// be just removed in the future
383-
} else {
384-
database.delete(database.exercises).go();
385-
await prefs.setInt(PREFS_EXERCISE_CACHE_VERSION, CACHE_VERSION);
386-
}
387-
}
388-
389365
Future<void> initCacheTimesLocalPrefs({forceInit = false}) async {
390366
final prefs = await SharedPreferences.getInstance();
391367

392-
// TODO: The exercise data was previously saved in PREFS_EXERCISES. This
393-
// can now be deleted. After some time when we can be sure all users
394-
// have updated their app, we can also remove this line and the
395-
// PREFS_EXERCISES constant
396-
if (prefs.containsKey(PREFS_EXERCISES)) {
397-
prefs.remove(PREFS_EXERCISES);
398-
}
399-
400368
final initDate = DateTime(2023, 1, 1).toIso8601String();
401369

402370
if (forceInit || !prefs.containsKey(PREFS_LAST_UPDATED_MUSCLES)) {
@@ -429,7 +397,6 @@ class ExercisesProvider with ChangeNotifier {
429397
clear();
430398

431399
await initCacheTimesLocalPrefs();
432-
await checkExerciseCacheVersion();
433400

434401
// Load categories, muscles, equipment and languages
435402
await Future.wait([

0 commit comments

Comments
 (0)