Skip to content

Commit

Permalink
[refactor] Sorting the values to update by period in ascending order
Browse files Browse the repository at this point in the history
* This will check the smallest periods first
  • Loading branch information
didierofrivia committed Aug 25, 2023
1 parent 156e644 commit 9515990
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions limitador/src/storage/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,17 @@ impl CounterStorage for InMemoryStorage {
}

// Update and check counters
counter_values_to_update.sort_by(|a, b| a.1.limit().seconds().cmp(&b.1.limit().seconds()));

for (expiring_value, counter) in counter_values_to_update {
if let Some(limited) = check_post_update(&counter, expiring_value, delta) {
return Ok(limited);
}
}

qualified_counter_values_to_updated
.sort_by(|a, b| a.1.limit().seconds().cmp(&b.1.limit().seconds()));

for (arc_expiring_value, counter) in qualified_counter_values_to_updated {
if let Some(limited) = check_post_update(&counter, &arc_expiring_value, delta) {
return Ok(limited);
Expand Down

0 comments on commit 9515990

Please sign in to comment.