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

View File

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