mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-01 23:13:16 +02:00
Fix GRPC with files not refreshing, and tight render loop
This commit is contained in:
@@ -185,29 +185,39 @@ impl GrpcHandle {
|
||||
pub async fn services_from_files(
|
||||
&mut self,
|
||||
id: &str,
|
||||
uri: &str,
|
||||
paths: Vec<PathBuf>,
|
||||
) -> Result<Vec<ServiceDefinition>, String> {
|
||||
let pool_key = format!(
|
||||
"{}-{}",
|
||||
id,
|
||||
paths
|
||||
.iter()
|
||||
.map(|p| p.to_string_lossy().to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join(":")
|
||||
);
|
||||
let pool = fill_pool_from_files(&self.app_handle, paths).await?;
|
||||
let uri = uri_from_str(uri)?;
|
||||
self.pools.insert(self.get_pool_key(id, &uri), pool.clone());
|
||||
self.pools.insert(pool_key, pool.clone());
|
||||
Ok(self.services_from_pool(&pool))
|
||||
}
|
||||
|
||||
pub async fn services_from_reflection(
|
||||
&mut self,
|
||||
id: &str,
|
||||
uri: &str,
|
||||
) -> Result<Vec<ServiceDefinition>, String> {
|
||||
// Short-circuit if no URL is set
|
||||
if uri.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
let uri = uri_from_str(uri)?;
|
||||
let pool = fill_pool(&uri).await?;
|
||||
self.pools.insert(self.get_pool_key(id, &uri), pool.clone());
|
||||
let pool_key = format!("{}-{}", id, uri);
|
||||
self.pools.insert(pool_key, pool.clone());
|
||||
Ok(self.services_from_pool(&pool))
|
||||
}
|
||||
|
||||
fn get_pool_key(&self, id: &str, uri: &Uri) -> String {
|
||||
format!("{}-{}", id, uri)
|
||||
}
|
||||
|
||||
fn services_from_pool(&self, pool: &DescriptorPool) -> Vec<ServiceDefinition> {
|
||||
pool.services()
|
||||
.map(|s| {
|
||||
@@ -274,6 +284,6 @@ fn uri_from_str(uri_str: &str) -> Result<Uri, String> {
|
||||
Err(err) => {
|
||||
// Uri::from_str basically only returns "invalid format" so we add more context here
|
||||
Err(format!("Failed to parse URL, {}", err.to_string()))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,12 +134,7 @@ async fn cmd_grpc_reflect(
|
||||
let req = get_grpc_request(&window, request_id)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
// Short-circuit if no URL is set
|
||||
if req.url.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
|
||||
let uri = safe_uri(req.url.as_str());
|
||||
if proto_files.len() > 0 {
|
||||
grpc_handle
|
||||
@@ -147,7 +142,6 @@ async fn cmd_grpc_reflect(
|
||||
.await
|
||||
.services_from_files(
|
||||
&req.id,
|
||||
uri.as_str(),
|
||||
proto_files
|
||||
.iter()
|
||||
.map(|p| PathBuf::from_str(p).unwrap())
|
||||
|
||||
Reference in New Issue
Block a user