Fix liberated status cache
This commit is contained in:
parent
d848c1a499
commit
9559109aa8
@ -32,6 +32,8 @@ namespace LibationWinForms
|
||||
|
||||
#region Model properties exposed to the view
|
||||
private Image _cover;
|
||||
|
||||
private DateTime lastStatusUpdate = default;
|
||||
private LiberatedStatus _bookStatus;
|
||||
private LiberatedStatus? _pdfStatus;
|
||||
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
|
||||
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
|
||||
{
|
||||
@ -93,6 +104,7 @@ namespace LibationWinForms
|
||||
{
|
||||
DownloadInProgress = true;
|
||||
await BookLiberation.ProcessorAutomationController.BackupSingleBookAsync(LibraryBook);
|
||||
UpdateLiberatedStatus();
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -114,10 +126,6 @@ namespace LibationWinForms
|
||||
LibraryBook = libraryBook;
|
||||
_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
|
||||
{
|
||||
(bool isDefault, byte[] picture) = PictureStorage.GetPicture(new PictureDefinition(Book.PictureId, PictureSize._80x80));
|
||||
@ -223,6 +231,14 @@ namespace LibationWinForms
|
||||
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
|
||||
|
||||
#region Data Sorting
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user