improve performance of helper method

- compare integers instead of Strings
- cache results per day
This commit is contained in:
NBA2K1 2025-12-30 02:44:45 +01:00
parent a63f0d67bd
commit c8328fa347

View file

@ -233,8 +233,12 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> {
); );
} }
final Map<String, List<Manga>> _dayCache = {};
List<Manga> _getEntriesForDay(DateTime day, List<Manga> data) { List<Manga> _getEntriesForDay(DateTime day, List<Manga> data) {
return data.where((e) { final key = "${day.year}-${day.month}-${day.day}";
if (_dayCache.containsKey(key)) return _dayCache[key]!;
final result = data.where((e) {
final lastChapter = e.chapters final lastChapter = e.chapters
.filter() .filter()
.sortByDateUploadDesc() .sortByDateUploadDesc()
@ -244,10 +248,12 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> {
? DateTime.fromMillisecondsSinceEpoch(lastDate) ? DateTime.fromMillisecondsSinceEpoch(lastDate)
: DateTime.now(); : DateTime.now();
final temp = start.add(Duration(days: e.smartUpdateDays!)); final temp = start.add(Duration(days: e.smartUpdateDays!));
final predictedDay = "${temp.year}-${temp.month}-${temp.day}"; return temp.year == day.year &&
final selectedDay = "${day.year}-${day.month}-${day.day}"; temp.month == day.month &&
return predictedDay == selectedDay; temp.day == day.day;
}).toList(); }).toList();
_dayCache[key] = result;
return result;
} }
List<Manga> _getEntriesForRange( List<Manga> _getEntriesForRange(