1
0
forked from firka/firka

fix(cache): fix off-by-one in timetable range delete

This commit is contained in:
2026-09-16 14:27:40 +02:00
parent 609f79c3b9
commit 5a15894833

View File

@@ -637,10 +637,26 @@ class KretaClient {
DateTime to,
List<LessonCacheModel> caches,
) async {
late int existingCount;
late int deletedCount;
isarInit.writeTxnSync(() {
cache.getTimeTable().and().between(from, to).deleteAllSync();
// NOT between(from, to): it's inclusive of `to`'s whole day, but
// `to` here is exclusive (matches what was actually fetched) — the
// inclusive version deleted a day beyond what `caches` covers.
final scope = cache.getTimeTable().and().startBetween(
from.getMidnight(),
to.getMidnight(),
includeUpper: false,
);
existingCount = scope.countSync();
deletedCount = scope.deleteAllSync();
isarInit.lessonCacheModels.putAllSync(caches);
});
logger.fine(
"[RenewCache] _replaceTimetableRange $from..$to: "
"existing=$existingCount deleted=$deletedCount inserting=${caches.length}",
);
initData.homeRefreshCubit.requestRefresh();
return caches;
}