Skip to content

Commit

Permalink
Avoid invoking the script with an empty batch
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnaps committed Apr 30, 2024
1 parent f7b4b99 commit c5212cf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion limitador/src/storage/redis/redis_cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ async fn update_counters<C: ConnectionLike>(
let redis_script = redis::Script::new(BATCH_UPDATE_COUNTERS);
let mut script_invocation = redis_script.prepare_invoke();

let mut res: Vec<(Counter, i64, i64)> = Vec::new();
let mut res: Vec<(Counter, i64, i64)> = Vec::with_capacity(counters_and_deltas.len());
if counters_and_deltas.is_empty() {
return Ok(res);
}

for (counter, delta) in counters_and_deltas {
let delta = delta.pending_writes().expect("State machine is wrong!");
if delta > 0 {
Expand Down

0 comments on commit c5212cf

Please sign in to comment.