From 320f5f4720dc251a14bcf743b53995db616aa9a9 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Tue, 12 Sep 2023 07:37:33 +0200 Subject: [PATCH] Remove unnecessary clones --- src/cache/cacher.rs | 8 ++++---- src/server/routes/search.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cache/cacher.rs b/src/cache/cacher.rs index 900affc..7839b6e 100644 --- a/src/cache/cacher.rs +++ b/src/cache/cacher.rs @@ -62,17 +62,17 @@ impl Cache { /// * `url` - It takes the url as a String. pub async fn cache_results( &mut self, - search_results: SearchResults, + search_results: &SearchResults, url: &str, ) -> Result<(), Report> { match self { Cache::Redis(redis_cache) => { - let json = serde_json::to_string(&search_results) + let json = serde_json::to_string(search_results) .map_err(|_| PoolError::SerializationError)?; redis_cache.cache_results(&json, url).await } Cache::InMemory(cache) => { - cache.insert(url.to_string(), search_results); + cache.insert(url.to_string(), search_results.clone()); Ok(()) } } @@ -102,7 +102,7 @@ impl SharedCache { /// `SearchResults` as the value. pub async fn cache_results( &self, - search_results: SearchResults, + search_results: &SearchResults, url: &str, ) -> Result<(), Report> { let mut mut_cache = self.cache.lock().await; diff --git a/src/server/routes/search.rs b/src/server/routes/search.rs index 27949f5..1c1cff1 100644 --- a/src/server/routes/search.rs +++ b/src/server/routes/search.rs @@ -208,7 +208,7 @@ async fn results( results.set_disallowed(); results.add_style(&config.style); results.set_page_query(query); - cache.cache_results(results.clone(), &url).await?; + cache.cache_results(&results, &url).await?; return Ok(results); } } @@ -256,7 +256,7 @@ async fn results( results.set_filtered(); } results.add_style(&config.style); - cache.cache_results(results.clone(), &url).await?; + cache.cache_results(&results, &url).await?; Ok(results) } }