Zsombor Gegesy
commited on
Commit
•
320f5f4
1
Parent(s):
519ebe0
Remove unnecessary clones
Browse files- src/cache/cacher.rs +4 -4
- src/server/routes/search.rs +2 -2
src/cache/cacher.rs
CHANGED
@@ -62,17 +62,17 @@ impl Cache {
|
|
62 |
/// * `url` - It takes the url as a String.
|
63 |
pub async fn cache_results(
|
64 |
&mut self,
|
65 |
-
search_results: SearchResults,
|
66 |
url: &str,
|
67 |
) -> Result<(), Report<PoolError>> {
|
68 |
match self {
|
69 |
Cache::Redis(redis_cache) => {
|
70 |
-
let json = serde_json::to_string(
|
71 |
.map_err(|_| PoolError::SerializationError)?;
|
72 |
redis_cache.cache_results(&json, url).await
|
73 |
}
|
74 |
Cache::InMemory(cache) => {
|
75 |
-
cache.insert(url.to_string(), search_results);
|
76 |
Ok(())
|
77 |
}
|
78 |
}
|
@@ -102,7 +102,7 @@ impl SharedCache {
|
|
102 |
/// `SearchResults` as the value.
|
103 |
pub async fn cache_results(
|
104 |
&self,
|
105 |
-
search_results: SearchResults,
|
106 |
url: &str,
|
107 |
) -> Result<(), Report<PoolError>> {
|
108 |
let mut mut_cache = self.cache.lock().await;
|
|
|
62 |
/// * `url` - It takes the url as a String.
|
63 |
pub async fn cache_results(
|
64 |
&mut self,
|
65 |
+
search_results: &SearchResults,
|
66 |
url: &str,
|
67 |
) -> Result<(), Report<PoolError>> {
|
68 |
match self {
|
69 |
Cache::Redis(redis_cache) => {
|
70 |
+
let json = serde_json::to_string(search_results)
|
71 |
.map_err(|_| PoolError::SerializationError)?;
|
72 |
redis_cache.cache_results(&json, url).await
|
73 |
}
|
74 |
Cache::InMemory(cache) => {
|
75 |
+
cache.insert(url.to_string(), search_results.clone());
|
76 |
Ok(())
|
77 |
}
|
78 |
}
|
|
|
102 |
/// `SearchResults` as the value.
|
103 |
pub async fn cache_results(
|
104 |
&self,
|
105 |
+
search_results: &SearchResults,
|
106 |
url: &str,
|
107 |
) -> Result<(), Report<PoolError>> {
|
108 |
let mut mut_cache = self.cache.lock().await;
|
src/server/routes/search.rs
CHANGED
@@ -208,7 +208,7 @@ async fn results(
|
|
208 |
results.set_disallowed();
|
209 |
results.add_style(&config.style);
|
210 |
results.set_page_query(query);
|
211 |
-
cache.cache_results(results
|
212 |
return Ok(results);
|
213 |
}
|
214 |
}
|
@@ -256,7 +256,7 @@ async fn results(
|
|
256 |
results.set_filtered();
|
257 |
}
|
258 |
results.add_style(&config.style);
|
259 |
-
cache.cache_results(results
|
260 |
Ok(results)
|
261 |
}
|
262 |
}
|
|
|
208 |
results.set_disallowed();
|
209 |
results.add_style(&config.style);
|
210 |
results.set_page_query(query);
|
211 |
+
cache.cache_results(&results, &url).await?;
|
212 |
return Ok(results);
|
213 |
}
|
214 |
}
|
|
|
256 |
results.set_filtered();
|
257 |
}
|
258 |
results.add_style(&config.style);
|
259 |
+
cache.cache_results(&results, &url).await?;
|
260 |
Ok(results)
|
261 |
}
|
262 |
}
|