Fix: Sync Log und verwaise Einträge
CI / build-and-test (push) Canceled after 0s

This commit is contained in:
2026-09-07 17:09:38 +02:00
parent 835cccadec
commit 86e114580f
12 changed files with 145 additions and 12 deletions
+19 -2
View File
@@ -118,11 +118,20 @@ public class UntisSyncService : IDisposable
var diffResult = _diffService.Diff(events, previousSnapshot, confirmedMappings, today,
existingSupervisionDuties: _supervisionDuties.GetAll(), freeDates: BuildFreeDates(today));
var savedSubstitutionCount = 0;
foreach (var candidate in diffResult.SubstitutionsToSave)
{
var existing = candidate.ExternalId is not null ? _substitutions.GetByExternalId(candidate.ExternalId) : null;
if (existing is not null) candidate.Id = existing.Id;
// Der Diff liefert auch weiterhin bestehende WebUntis-Abweichungen als Kandidaten.
// Ein unverändertes Upsert würde über Repository.OnChange bei jedem Poll erneut ein
// Sync-Ereignis erzeugen und bei vielen aktiven Abweichungen das Protokoll fluten.
if (existing is not null)
{
candidate.Id = existing.Id;
if (SubstitutionContentEquals(existing, candidate)) continue;
}
_substitutions.Save(candidate);
savedSubstitutionCount++;
}
// Zuvor automatisch erzeugte Einträge, die jetzt nicht (mehr) gebraucht werden (siehe
// UntisDiffResult.SubstitutionExternalIdsToDelete) - existiert keiner mit dieser
@@ -135,9 +144,17 @@ public class UntisSyncService : IDisposable
foreach (var snapshot in diffResult.SnapshotToSave) _snapshots.Save(snapshot);
foreach (var id in diffResult.SnapshotIdsToDelete) _snapshots.Delete(id);
return new UntisPollResult(events.Count, diffResult.SubstitutionsToSave.Count);
return new UntisPollResult(events.Count, savedSubstitutionCount);
}
private static bool SubstitutionContentEquals(SubstitutionEntry left, SubstitutionEntry right) =>
left.Date == right.Date && left.Kind == right.Kind &&
left.PeriodNumber == right.PeriodNumber && left.AfterPeriod == right.AfterPeriod &&
left.FromPeriod == right.FromPeriod && left.ToPeriod == right.ToPeriod &&
left.IsAllDay == right.IsAllDay && left.GroupId == right.GroupId &&
left.GroupLabel == right.GroupLabel && left.Description == right.Description &&
left.Notes == right.Notes && left.ExternalId == right.ExternalId;
// Ferien-/Feiertagstage im relevanten Zeitfenster (deutlich über das Lookahead-Fenster
// hinaus, kostet bei kleinen Ferienlisten nichts) - verhindert, dass die aktive
// "fehlt komplett im Feed"-Prüfung in UntisDiffService Ferientage fälschlich als Ausfall