Optimise loop
@@ -375,8 +375,8 @@ impl Transform for SimpleRedisCache {
}
async fn transform<'a>(&'a mut self, mut message_wrapper: Wrapper<'a>) -> ChainResponse {
- let mut updates = 0_i32;
- {
+ let mut updates = false;
+
for m in &mut message_wrapper.messages {
if let RawFrame::Cassandra(Frame {
opcode: Opcode::Query,
@@ -385,13 +385,14 @@ impl Transform for SimpleRedisCache {
{
m.generate_message_details_query();
if m.get_query_type() == QueryType::Write {
- updates += 1;
- }
+ updates = true;
+ break;
}
}
}
- if updates == 0 {
+ // If there are no write queries (all queries are reads) we can use the cache
+ if !updates {
match self
.get_or_update_from_cache(message_wrapper.messages.clone())
.await
