Skip to content

Commit ae86515

Browse files
committed
clean up for better readablility
1 parent 8ff1ada commit ae86515

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

server/src/handlers/airplane.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ impl FlightService for AirServiceImpl {
252252
query.end.to_rfc3339(),
253253
ticket.query,
254254
)
255-
.await {
255+
.await
256+
{
256257
log::error!("{}", err);
257258
};
258259

server/src/handlers/http/cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ pub async fn list(req: HttpRequest) -> Result<impl Responder, PostError> {
5050
.await
5151
.map_err(PostError::CacheError)?;
5252

53-
let size = cache.current_size();
53+
let size = cache.used_cache_size();
5454
let queries = cache.queries();
5555

5656
let out = json!({
57-
"current_cache_size": size,
57+
"used_capacity": size,
5858
"cache": queries
5959
});
6060

server/src/handlers/http/query.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<impl Respon
141141
query.end.to_rfc3339(),
142142
query_request.query,
143143
)
144-
.await {
144+
.await
145+
{
145146
log::error!("{}", err);
146147
};
147148

@@ -198,10 +199,11 @@ pub async fn put_results_in_cache(
198199
}
199200
// do cache
200201
(Some(should_cache), Some(query_cache_manager)) => {
201-
202202
if should_cache != "true" {
203203
log::error!("value of cache results header is false");
204-
return Err(QueryError::CacheError(CacheError::Other("should not cache results")));
204+
return Err(QueryError::CacheError(CacheError::Other(
205+
"should not cache results",
206+
)));
205207
}
206208

207209
let user_id = user_id.ok_or(CacheError::Other("User Id not provided"))?;
@@ -222,9 +224,7 @@ pub async fn put_results_in_cache(
222224
// fallthrough
223225
Ok(())
224226
}
225-
(None, _) => {
226-
Ok(())
227-
}
227+
(None, _) => Ok(()),
228228
}
229229
}
230230

@@ -250,7 +250,9 @@ pub async fn get_results_from_cache(
250250
(Some(should_show), Some(query_cache_manager)) => {
251251
if should_show != "true" {
252252
log::error!("value of show cached header is false");
253-
return Err(QueryError::CacheError(CacheError::Other("should not return cached results")));
253+
return Err(QueryError::CacheError(CacheError::Other(
254+
"should not return cached results",
255+
)));
254256
}
255257

256258
let user_id =

server/src/querycache.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ pub const QUERY_CACHE_FILENAME: &str = ".cache.json";
4040
pub const QUERY_CACHE_META_FILENAME: &str = ".cache_meta.json";
4141
pub const CURRENT_QUERY_CACHE_VERSION: &str = "v1";
4242

43-
// .cache.json
4443
#[derive(Default, Clone, serde::Deserialize, serde::Serialize, Debug, Hash, Eq, PartialEq)]
4544
pub struct CacheMetadata {
4645
pub query: String,
@@ -80,7 +79,7 @@ impl QueryCache {
8079
self.files.get(&key).cloned()
8180
}
8281

83-
pub fn current_size(&self) -> u64 {
82+
pub fn used_cache_size(&self) -> u64 {
8483
self.current_size
8584
}
8685

@@ -137,7 +136,7 @@ impl QueryCacheMeta {
137136
pub struct QueryCacheManager {
138137
filesystem: LocalFileSystem,
139138
cache_path: PathBuf, // refers to the path passed in the env var
140-
cache_capacity: u64,
139+
total_cache_capacity: u64,
141140
semaphore: Mutex<()>,
142141
}
143142

@@ -172,7 +171,7 @@ impl QueryCacheManager {
172171
Self {
173172
filesystem: LocalFileSystem::new(),
174173
cache_path,
175-
cache_capacity: CONFIG.parseable.query_cache_size,
174+
total_cache_capacity: CONFIG.parseable.query_cache_size,
176175
semaphore: Mutex::new(()),
177176
}
178177
});
@@ -292,7 +291,7 @@ impl QueryCacheManager {
292291
let file_size = std::fs::metadata(file_path)?.len();
293292
let mut cache = self.get_cache(stream, user_id).await?;
294293

295-
while cache.current_size + file_size > self.cache_capacity {
294+
while cache.current_size + file_size > self.total_cache_capacity {
296295
if let Some((_, file_for_removal)) = cache.files.pop_lru() {
297296
let lru_file_size = fs::metadata(&file_for_removal).await?.len();
298297
cache.current_size = cache.current_size.saturating_sub(lru_file_size);

0 commit comments

Comments
 (0)