refactor: Move quota_needs_update calculation to a separate function (#5683)

And add a unit test for this function. At least this way we protect from the recently fixed bug when
a wrong comparison operator was used.
This commit is contained in:
iequidoo
2024-06-27 16:31:01 -03:00
committed by iequidoo
parent ee2fffb52b
commit 170cbb6635
3 changed files with 38 additions and 22 deletions

View File

@@ -541,18 +541,10 @@ impl Context {
}
// update quota (to send warning if full) - but only check it once in a while
let quota_needs_update = {
let quota = self.quota.read().await;
quota
.as_ref()
.filter(|quota| {
time_elapsed(&quota.modified)
< Duration::from_secs(DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT)
})
.is_none()
};
if quota_needs_update {
if self
.quota_needs_update(DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT)
.await
{
if let Err(err) = self.update_recent_quota(&mut session).await {
warn!(self, "Failed to update quota: {err:#}.");
}