Untis-API Optimierung.

This commit is contained in:
2026-08-24 22:33:30 +02:00
parent 1db16f8b69
commit 17475a781f
9 changed files with 109 additions and 53 deletions
@@ -1,4 +1,3 @@
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -60,16 +59,14 @@ public partial class WebUntisAbsenceComparisonViewModel : ObservableObject
var localSessions = _sessions.GetByGroup(_group.Id)
.Where(x => x.Date >= start && x.Date <= end).GroupBy(x => x.Date)
.ToDictionary(x => x.Key, x => x.First());
var loaded = new ConcurrentBag<(Student Student, UntisStudentAbsenceDto Absence)>();
var linked = courseStudents.Select(student => (Student: student, Key: StudentKey(student)))
.Where(x => x.Key is not null).ToList();
await Parallel.ForEachAsync(linked, new ParallelOptions { MaxDegreeOfParallelism = 4 }, async (item, token) =>
{
var report = await _untis.GetAbsencesAsync(item.Key!.Value, start, end, token);
foreach (var absence in report.Absences) loaded.Add((item.Student, absence));
});
.Where(x => x.Key is not null).ToDictionary(x => x.Key!.Value, x => x.Student);
var absences = await _untis.GetAbsencesAsync(start, end);
var loaded = absences.Where(absence => linked.ContainsKey(absence.StudentKey))
.Select(absence => (Student: linked[absence.StudentKey], Absence: absence))
.OrderBy(x => x.Absence.Date).ThenBy(x => x.Student.FullName);
foreach (var item in loaded.OrderBy(x => x.Absence.Date).ThenBy(x => x.Student.FullName))
foreach (var item in loaded)
{
if (!TryDate(item.Absence.Date, out var date)) continue;
localSessions.TryGetValue(date, out var session);