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
|
|
@ -44,16 +44,18 @@ namespace LibationAvalonia.ViewModels
|
|||
|
||||
private void Configure_BackupCounts()
|
||||
{
|
||||
MainWindow.LibraryLoaded += (_, e) => setBackupCounts(e.Where(l => !l.Book.IsEpisodeParent()));
|
||||
LibraryCommands.LibrarySizeChanged += (_,_) => setBackupCounts();
|
||||
LibraryCommands.BookUserDefinedItemCommitted += (_, _) => setBackupCounts();
|
||||
LibraryCommands.LibrarySizeChanged += async (object _, List<LibraryBook> libraryBooks)
|
||||
=> await SetBackupCountsAsync(libraryBooks);
|
||||
|
||||
//Pass null to the setup count to get the whole library.
|
||||
LibraryCommands.BookUserDefinedItemCommitted += async (_, _)
|
||||
=> await SetBackupCountsAsync(null);
|
||||
}
|
||||
|
||||
private async void setBackupCounts(IEnumerable<LibraryBook> libraryBooks = null)
|
||||
public async Task SetBackupCountsAsync(IEnumerable<LibraryBook> libraryBooks)
|
||||
{
|
||||
if (updateCountsTask?.IsCompleted ?? true)
|
||||
{
|
||||
libraryBooks ??= DbContexts.GetLibrary_Flat_NoTracking();
|
||||
updateCountsTask = Task.Run(() => LibraryCommands.GetCounts(libraryBooks));
|
||||
var stats = await updateCountsTask;
|
||||
await Dispatcher.UIThread.InvokeAsync(() => LibraryStats = stats);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
using ApplicationServices;
|
||||
using DataLayer;
|
||||
using LibationAvalonia.Views;
|
||||
using LibationFileManager;
|
||||
using ReactiveUI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LibationAvalonia.ViewModels
|
||||
{
|
||||
|
|
@ -34,9 +36,8 @@ namespace LibationAvalonia.ViewModels
|
|||
Configure_VisibleBooks();
|
||||
}
|
||||
|
||||
private async void LibraryCommands_LibrarySizeChanged(object sender, System.EventArgs e)
|
||||
private async void LibraryCommands_LibrarySizeChanged(object sender, List<LibraryBook> fullLibrary)
|
||||
{
|
||||
var fullLibrary = await System.Threading.Tasks.Task.Run(() => DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
|
||||
await ProductsDisplay.UpdateGridAsync(fullLibrary);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue