Skip to content

Commit

Permalink
[cooling] Only start coolling when memo reviewed
Browse files Browse the repository at this point in the history
  • Loading branch information
Banyc committed Mar 25, 2021
1 parent 9373717 commit bf43e18
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/UnforgettableMemo.Shared/MemoScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void OrderByRetrievability()

public Memo GetLeastRetrievedMemo()
{
if (this.settings.CoolingTimeSpan > DateTime.UtcNow - this.settings.LastGetLeastRetrievedMemoTime)
if (this.settings.CoolingTimeSpan > DateTime.UtcNow - this.settings.LastCoolingStartTime)
{
return null;
}
Expand All @@ -44,7 +44,6 @@ public Memo GetLeastRetrievedMemo()
else if (this.energyScheduler.TryConsumeEnergy(this.settings.EnergyCost))
{
this.OrganizeMemos();
this.settings.LastGetLeastRetrievedMemoTime = DateTime.UtcNow;
return this.Memos.First();
}
else
Expand All @@ -53,6 +52,11 @@ public Memo GetLeastRetrievedMemo()
}
}

public void StartCooling()
{
this.settings.LastCoolingStartTime = DateTime.UtcNow;
}

// get new memo that has just been added to the list
public Memo GetBlankMemo()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public TimeSpan CoolingTimeSpan
this.CoolingTimeSpanSeconds = value.TotalSeconds;
}
}
public DateTime LastGetLeastRetrievedMemoTime { get; set; }
public DateTime LastCoolingStartTime { get; set; }
public int EnergyCost { get; set; } = 3; // per memo retrieving
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private void btnDelete_Click(object sender, RoutedEventArgs e)
// update the memory state of the displaying memo and display the least memorized memo
private void btnReview_Click(object sender, RoutedEventArgs e)
{
this.memoScheduler.StartCooling();
this.viewModel.DisplayingMemo.Review();
UpdateViewModel();
UpdateView();
Expand Down

0 comments on commit bf43e18

Please sign in to comment.