Skip to content

Commit

Permalink
Only write out meaningful deltas
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnaps committed Apr 5, 2024
1 parent e4f54b2 commit 26447a3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions limitador/src/storage/redis/redis_cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl CachedRedisStorage {
DEFAULT_TTL_RATIO_CACHED_COUNTERS,

Check warning on line 203 in limitador/src/storage/redis/redis_cached.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador/src/storage/redis/redis_cached.rs

Check warning on line 203 in limitador/src/storage/redis/redis_cached.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador/src/storage/redis/redis_cached.rs
Duration::from_millis(DEFAULT_RESPONSE_TIMEOUT_MS),
)
.await
.await
}

async fn new_with_options(
Expand All @@ -224,7 +224,7 @@ impl CachedRedisStorage {
response_timeout,

Check warning on line 224 in limitador/src/storage/redis/redis_cached.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador/src/storage/redis/redis_cached.rs

Check warning on line 224 in limitador/src/storage/redis/redis_cached.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador/src/storage/redis/redis_cached.rs
Duration::from_secs(5),
)
.await?;
.await?;

let partitioned = Arc::new(AtomicBool::new(false));
let async_redis_storage =
Expand All @@ -250,11 +250,14 @@ impl CachedRedisStorage {
};
let now = SystemTime::now();
for (counter, delta) in counters {
storage
.update_counter(&counter, delta.value_at(now))
.await
.or_else(|err| if err.is_transient() { Ok(()) } else { Err(err) })
.expect("Unrecoverable Redis error!");
let delta = delta.value_at(now);
if delta > 0 {
storage
.update_counter(&counter, delta)
.await
.or_else(|err| if err.is_transient() { Ok(()) } else { Err(err) })
.expect("Unrecoverable Redis error!");
}
}
}
interval.tick().await;
Expand Down Expand Up @@ -388,7 +391,7 @@ impl CachedRedisStorageBuilder {
self.ttl_ratio_cached_counters,

Check warning on line 391 in limitador/src/storage/redis/redis_cached.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador/src/storage/redis/redis_cached.rs

Check warning on line 391 in limitador/src/storage/redis/redis_cached.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador/src/storage/redis/redis_cached.rs
self.response_timeout,
)
.await
.await
}
}

Expand Down

0 comments on commit 26447a3

Please sign in to comment.