From 9bcd2b8104d8200a48cf6d880325667e2978415a Mon Sep 17 00:00:00 2001 From: Pascal Seitz Date: Thu, 2 Jun 2022 13:37:52 +0800 Subject: [PATCH] fix read_block_async --- src/store/reader.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/store/reader.rs b/src/store/reader.rs index 46eae3cc8..a0d4654c2 100644 --- a/src/store/reader.rs +++ b/src/store/reader.rs @@ -307,6 +307,7 @@ impl StoreReader { /// /// Loads and decompresses a block asynchronously. async fn read_block_async(&self, checkpoint: &Checkpoint) -> crate::AsyncIoResult { + let cache_key = checkpoint.byte_range.start; if let Some(block) = self.cache.get_from_cache(checkpoint.byte_range.start) { return Ok(block.clone()); } @@ -316,8 +317,12 @@ impl StoreReader { .slice(checkpoint.byte_range.clone()) .read_bytes_async() .await?; - let block = self.decompress_block(compressed_block, checkpoint.byte_range.start)?; - Ok(block) + + let decompressed_block = OwnedBytes::new(self.compressor.decompress(compressed_block.as_ref())?); + + self.cache.put_into_cache(cache_key, decompressed_block.clone()); + + Ok(decompressed_block) } /// Fetches a document asynchronously.