Skip to content

Commit

Permalink
fix: safety check
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesvedder committed Jul 22, 2024
1 parent 7ce484f commit 978807c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/lib/util/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ class Cache {
if (backupSubject != null) {
// Only take progress from cached subject and rest from backup,
// as the cached subject might be outdated or corrupted

// compare IDs to make sure we are not mixing up subjects
// If IDs do not match we should not use the cached subject
if (backupSubject.id != cachedSubject['id']) {
throw Exception(
"Cached subject ID does not match remote subject ID",
);
}
final cachedProgress = (cachedSubject['progress'] as List?)
?.map((e) => SubjectProgress.fromJson(e as Map<String, dynamic>))
.toList();
Expand Down

0 comments on commit 978807c

Please sign in to comment.