Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] Simplifying fn check_and_update #190

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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