Skip to content

Commit a88356c

Browse files
committed
clean up for better readablility
1 parent 341ee6e commit a88356c

File tree

6 files changed

+19
-20
lines changed

6 files changed

+19
-20
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/ingest.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,6 @@ pub enum PostError {
433433
Invalid(#[from] anyhow::Error),
434434
#[error("{0}")]
435435
CreateStream(#[from] CreateStreamError),
436-
#[error("Error: {0}")]
437-
Error(std::io::Error),
438436
#[allow(unused)]
439437
#[error("Error: {0}")]
440438
CustomError(String),
@@ -467,7 +465,6 @@ impl actix_web::ResponseError for PostError {
467465
PostError::ObjectStorageError(_) => StatusCode::INTERNAL_SERVER_ERROR,
468466
PostError::DashboardError(_) => StatusCode::INTERNAL_SERVER_ERROR,
469467
PostError::FiltersError(_) => StatusCode::INTERNAL_SERVER_ERROR,
470-
PostError::Error(_) => StatusCode::INTERNAL_SERVER_ERROR,
471468
PostError::CacheError(_) => StatusCode::INTERNAL_SERVER_ERROR,
472469
}
473470
}

server/src/handlers/http/modal/query_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use crate::handlers::http::middleware::RouteExt;
2222
use crate::handlers::http::{base_path, cross_origin_config, API_BASE_PATH, API_VERSION};
2323

2424
use crate::rbac::role::Action;
25+
use crate::sync;
2526
use crate::users::dashboards::DASHBOARDS;
2627
use crate::users::filters::FILTERS;
27-
use crate::sync;
2828
use crate::{analytics, banner, metadata, metrics, migration, rbac, storage};
2929
use actix_web::web;
3030
use actix_web::web::ServiceConfig;

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: 5 additions & 6 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

@@ -151,7 +150,7 @@ impl QueryCacheManager {
151150
&format!(
152151
"{}.{}.parquet",
153152
hostname_unchecked(),
154-
Utc::now().timestamp().to_string()
153+
Utc::now().timestamp()
155154
),
156155
])
157156
}
@@ -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)