Fix liberated status cache

This commit is contained in:
Michael Bucari-Tovo 2022-05-10 00:19:45 -06:00
parent d848c1a499
commit 9559109aa8

View File

@ -32,6 +32,8 @@ namespace LibationWinForms
#region Model properties exposed to the view #region Model properties exposed to the view
private Image _cover; private Image _cover;
private DateTime lastStatusUpdate = default;
private LiberatedStatus _bookStatus; private LiberatedStatus _bookStatus;
private LiberatedStatus? _pdfStatus; private LiberatedStatus? _pdfStatus;
public Image Cover public Image Cover
@ -65,7 +67,16 @@ namespace LibationWinForms
// these 2 values being in 1 field is the trick behind getting the liberated+pdf 'stoplight' icon to draw. See: LiberateDataGridViewImageButtonCell.Paint // these 2 values being in 1 field is the trick behind getting the liberated+pdf 'stoplight' icon to draw. See: LiberateDataGridViewImageButtonCell.Paint
public (LiberatedStatus BookStatus, LiberatedStatus? PdfStatus) Liberate public (LiberatedStatus BookStatus, LiberatedStatus? PdfStatus) Liberate
{ {
get => (_bookStatus, _pdfStatus); get
{
//Cache these statuses for faster sorting.
if ((DateTime.Now - lastStatusUpdate).TotalSeconds > 2)
{
UpdateLiberatedStatus(notify: false);
lastStatusUpdate = DateTime.Now;
}
return (_bookStatus, _pdfStatus);
}
set set
{ {
@ -93,6 +104,7 @@ namespace LibationWinForms
{ {
DownloadInProgress = true; DownloadInProgress = true;
await BookLiberation.ProcessorAutomationController.BackupSingleBookAsync(LibraryBook); await BookLiberation.ProcessorAutomationController.BackupSingleBookAsync(LibraryBook);
UpdateLiberatedStatus();
} }
finally finally
{ {
@ -114,10 +126,6 @@ namespace LibationWinForms
LibraryBook = libraryBook; LibraryBook = libraryBook;
_memberValues = CreateMemberValueDictionary(); _memberValues = CreateMemberValueDictionary();
//Cache these statuses for faster sorting.
_bookStatus = LibraryCommands.Liberated_Status(LibraryBook.Book);
_pdfStatus = LibraryCommands.Pdf_Status(LibraryBook.Book);
// Get cover art. If it's default, subscribe to PictureCached // Get cover art. If it's default, subscribe to PictureCached
{ {
(bool isDefault, byte[] picture) = PictureStorage.GetPicture(new PictureDefinition(Book.PictureId, PictureSize._80x80)); (bool isDefault, byte[] picture) = PictureStorage.GetPicture(new PictureDefinition(Book.PictureId, PictureSize._80x80));
@ -223,6 +231,14 @@ namespace LibationWinForms
Committed?.Invoke(this, null); Committed?.Invoke(this, null);
} }
private void UpdateLiberatedStatus(bool notify = true)
{
_bookStatus = LibraryCommands.Liberated_Status(LibraryBook.Book);
_pdfStatus = LibraryCommands.Pdf_Status(LibraryBook.Book);
if (notify)
NotifyPropertyChanged(nameof(Liberate));
}
#endregion #endregion
#region Data Sorting #region Data Sorting