fix(ui): batch UI updates for bulk mark-as-read to prevent UI freeze (#786)

This commit is contained in:
Wynn Zeng
2026-01-28 03:25:05 +08:00
committed by GitHub
parent 7f8c6776fc
commit 4f65502c95
5 changed files with 73 additions and 9 deletions
@@ -685,6 +685,37 @@ public partial class MailListPageViewModel : MailBaseViewModel,
await ExecuteUIThread(() => { SetupTopBarActions(); });
}
protected override async void OnMailUpdated(IReadOnlyList<MailCopy> updatedMails)
{
base.OnMailUpdated(updatedMails);
if (updatedMails == null || updatedMails.Count == 0) return;
// Bulk update: do all changes in a single UI-thread invocation to avoid UI lockups when
// thousands of MailUpdatedMessage events would otherwise be processed one by one.
await ExecuteUIThread(() =>
{
foreach (var mail in updatedMails)
{
if (mail == null) continue;
// Avoid work for items not in the list.
if (!MailCollection.MailCopyIdHashSet.Contains(mail.UniqueId))
continue;
var container = MailCollection.GetMailItemContainer(mail.UniqueId);
if (container?.ItemViewModel != null)
{
container.ItemViewModel.MailCopy = mail;
container.ThreadViewModel?.NotifyPropertyChanges();
}
}
SetupTopBarActions();
});
}
protected override async void OnMailRemoved(MailCopy removedMail)
{
base.OnMailRemoved(removedMail);