Skip to content

Commit

Permalink
Remove vector if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
m30m committed Mar 27, 2024
1 parent 696dbdb commit f36c2bc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions auction-server/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,16 @@ impl Store {
let key = match &opportunity.params {
OpportunityParams::V1(params) => params.permission_key.clone(),
};
self.opportunity_store
.opportunities
.write()
.await
.entry(key)
.and_modify(|opps| opps.retain(|o| o != opportunity));
let mut write_guard = self.opportunity_store.opportunities.write().await;
let entry = write_guard.entry(key.clone());
if entry
.and_modify(|opps| opps.retain(|o| o != opportunity))
.or_default()
.is_empty()
{
write_guard.remove(&key);
}
drop(write_guard);
let now = OffsetDateTime::now_utc();
sqlx::query!(
"UPDATE opportunity SET removal_time = $1 WHERE id = $2 AND removal_time IS NULL",
Expand Down

0 comments on commit f36c2bc

Please sign in to comment.