feat(core): optimize query resource lifecycle
This commit is contained in:
1 parent
b4bd6c42a7
commit
295b67dd36
29 files changed
+1857
-335
No files matched your search
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
use base64::{engine::general_purpose::STANDARD as BASE64, Engine as _};
|
||||
use dbx_core::connection::AppState;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::State;
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -14,6 +14,9 @@ pub struct LoadTabRuntimeCacheResponse {
|
||||
pub column_count: i64,
|
||||
pub byte_size: i64,
|
||||
pub updated_at: String,
|
||||
pub created_at: i64,
|
||||
pub last_accessed_at: i64,
|
||||
pub owner_id: Option<String>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -23,9 +26,10 @@ pub async fn save_tab_runtime_cache(
|
||||
payload_base64: String,
|
||||
row_count: i64,
|
||||
column_count: i64,
|
||||
owner_id: Option<String>,
|
||||
) -> Result<(), String> {
|
||||
let payload = BASE64.decode(payload_base64).map_err(|e| e.to_string())?;
|
||||
state.storage.save_tab_runtime_cache(&key, payload, row_count, column_count).await
|
||||
state.storage.save_tab_runtime_cache(&key, payload, row_count, column_count, owner_id).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -41,9 +45,47 @@ pub async fn load_tab_runtime_cache(
|
||||
column_count: entry.column_count,
|
||||
byte_size: entry.byte_size,
|
||||
updated_at: entry.updated_at,
|
||||
created_at: entry.created_at,
|
||||
last_accessed_at: entry.last_accessed_at,
|
||||
owner_id: entry.owner_id,
|
||||
}))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn list_tab_runtime_cache_metadata(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
) -> Result<Vec<dbx_core::storage::TabRuntimeCacheMetadata>, String> {
|
||||
state.storage.list_tab_runtime_cache_metadata().await
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PruneTabRuntimeCacheRequest {
|
||||
pub live_keys: Vec<String>,
|
||||
pub max_bytes: i64,
|
||||
pub orphan_grace_ms: i64,
|
||||
pub max_age_ms: Option<i64>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn prune_tab_runtime_cache(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
request: PruneTabRuntimeCacheRequest,
|
||||
) -> Result<dbx_core::storage::TabRuntimeCachePruneResult, String> {
|
||||
state
|
||||
.storage
|
||||
.prune_tab_runtime_cache(request.live_keys, request.max_bytes, request.orphan_grace_ms, request.max_age_ms)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn delete_tab_runtime_cache_owner(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
owner_id: String,
|
||||
) -> Result<usize, String> {
|
||||
state.storage.delete_tab_runtime_cache_owner(&owner_id).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn delete_tab_runtime_cache(state: State<'_, Arc<AppState>>, key: String) -> Result<(), String> {
|
||||
state.storage.delete_tab_runtime_cache(&key).await
|
||||
|
||||
Reference in new issue
Block a user