Get full library in LibrarySizeChanged event and pass as EventArgs
There are multiple subscribers to LibraryCommands.LibrarySizeChanged, and each one calls GetLibrary_Flat_NoTracking(). Passing the full library as an event argument speeds up all operations which happen after the library size changes. Fix initial backup counts
This commit is contained in:
parent
2a25b7e0ad
commit
2d6120f0c4
9 changed files with 44 additions and 25 deletions
|
|
@ -17,7 +17,9 @@ namespace LibationWinForms
|
|||
beginPdfBackupsToolStripMenuItem.Format(0);
|
||||
|
||||
LibraryCommands.LibrarySizeChanged += setBackupCounts;
|
||||
LibraryCommands.BookUserDefinedItemCommitted += setBackupCounts;
|
||||
//Pass null to the runner to get the whole library.
|
||||
LibraryCommands.BookUserDefinedItemCommitted += (_, _)
|
||||
=> setBackupCounts(null, null);
|
||||
|
||||
updateCountsBw.DoWork += UpdateCountsBw_DoWork;
|
||||
updateCountsBw.RunWorkerCompleted += exportMenuEnable;
|
||||
|
|
@ -28,12 +30,12 @@ namespace LibationWinForms
|
|||
|
||||
private bool runBackupCountsAgain;
|
||||
|
||||
private void setBackupCounts(object _, object __)
|
||||
private void setBackupCounts(object _, List<LibraryBook> libraryBooks)
|
||||
{
|
||||
runBackupCountsAgain = true;
|
||||
|
||||
if (!updateCountsBw.IsBusy)
|
||||
updateCountsBw.RunWorkerAsync();
|
||||
updateCountsBw.RunWorkerAsync(libraryBooks);
|
||||
}
|
||||
|
||||
private void UpdateCountsBw_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
|
||||
|
|
@ -41,11 +43,7 @@ namespace LibationWinForms
|
|||
while (runBackupCountsAgain)
|
||||
{
|
||||
runBackupCountsAgain = false;
|
||||
|
||||
if (e.Argument is not IEnumerable<LibraryBook> lbs)
|
||||
lbs = DbContexts.GetLibrary_Flat_NoTracking();
|
||||
|
||||
e.Result = LibraryCommands.GetCounts(lbs);
|
||||
e.Result = LibraryCommands.GetCounts(e.Argument as IEnumerable<LibraryBook>);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue