Skip to content

Commit

Permalink
[refactor] Replacing nesting conditionals and calling once
Browse files Browse the repository at this point in the history
process_counter
  • Loading branch information
didierofrivia committed Jul 12, 2023
1 parent 4ac3535 commit 62c7308
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions limitador/src/storage/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,15 @@ impl CounterStorage for InMemoryStorage {
}
continue;
}
if let Some(limits) = limits_by_namespace.get(counter.limit().namespace()) {
if let Some(counters) = limits.get(counter.limit()) {
if let Some(expiring_value) = counters.get(&counter.into()) {
let value = expiring_value.value();
if let Some(Authorization::Limited(counter_limited)) =
process_counter(counter, value, delta)
{
if !load_counters {
return Ok(Authorization::Limited(counter_limited));
}
}
}
}
} else if let Some(limited) = process_counter(counter, 0, delta) {

let value = Some(limits_by_namespace
.get(counter.limit().namespace())
.and_then(|limits| limits.get(counter.limit()))
.and_then(|counters| counters.get(&counter.into()))
.map(|expiring_value| expiring_value.value())
.unwrap_or(0));

if let Some(limited) = process_counter(counter, value.unwrap(), delta) {
if !load_counters {
return Ok(limited);
}
Expand Down

0 comments on commit 62c7308

Please sign in to comment.