Improve grid update performance

This commit is contained in:
MBucari 2023-03-11 21:50:30 -07:00
parent 3f0e6b9ee5
commit eed42bd108
2 changed files with 4 additions and 9 deletions

View File

@ -132,7 +132,7 @@ namespace LibationAvalonia.ViewModels
//Add absent entries to grid, or update existing entry
var allEntries = SOURCE.BookEntries().ToList();
var seriesEntries = SOURCE.SeriesEntries().ToList();
var parentedEpisodes = dbBooks.ParentedEpisodes().ToList();
var parentedEpisodes = dbBooks.ParentedEpisodes().ToHashSet();
await Dispatcher.UIThread.InvokeAsync(() =>
{
@ -142,7 +142,7 @@ namespace LibationAvalonia.ViewModels
if (libraryBook.Book.IsProduct())
UpsertBook(libraryBook, existingEntry);
else if (parentedEpisodes.Any(lb => lb == libraryBook))
else if (parentedEpisodes.Contains(libraryBook))
//Only try to add or update is this LibraryBook is a know child of a parent
UpsertEpisode(libraryBook, existingEntry, seriesEntries, dbBooks);
}

View File

@ -265,9 +265,7 @@ namespace LibationWinForms.GridView
var allEntries = bindingList.AllItems().BookEntries();
var seriesEntries = bindingList.AllItems().SeriesEntries().ToList();
var parentedEpisodes = dbBooks.ParentedEpisodes().ToList();
var sw = new Stopwatch();
var parentedEpisodes = dbBooks.ParentedEpisodes().ToHashSet();
foreach (var libraryBook in dbBooks.OrderBy(e => e.DateAdded))
{
@ -278,14 +276,11 @@ namespace LibationWinForms.GridView
AddOrUpdateBook(libraryBook, existingEntry);
continue;
}
sw.Start();
if (parentedEpisodes.Any(lb => lb == libraryBook))
if (parentedEpisodes.Contains(libraryBook))
{
sw.Stop();
//Only try to add or update is this LibraryBook is a know child of a parent
AddOrUpdateEpisode(libraryBook, existingEntry, seriesEntries, dbBooks);
}
sw.Stop();
}
bindingList.SuspendFilteringOnUpdate = false;