Skip to content

Commit

Permalink
Merge pull request #190 from Kuadrant/refactoring-inmemory-check-and-…
Browse files Browse the repository at this point in the history
…update

[refactor] Simplifying fn check_and_update
  • Loading branch information
didierofrivia authored Jul 17, 2023
2 parents 4ac3535 + 3d7015a commit 775596d
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions limitador/src/storage/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,17 @@ 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 775596d

Please sign in to comment.