reused grpc connections, not a constant refreshes anymore, all fixed now, keep on fixing other bugs
This commit is contained in:
@@ -109,7 +109,9 @@ impl EventHandler {
|
||||
edit_mode_cooldown: false,
|
||||
ideal_cursor_column: 0,
|
||||
input_engine: InputEngine::new(400, 5000),
|
||||
auth_client: AuthClient::new().await?,
|
||||
auth_client: AuthClient::with_channel(
|
||||
grpc_client.channel()
|
||||
).await?,
|
||||
grpc_client,
|
||||
login_result_sender,
|
||||
register_result_sender,
|
||||
@@ -398,6 +400,7 @@ impl EventHandler {
|
||||
// Do NOT call the input engine here again. The top-level
|
||||
// process_key call above already ran for this key.
|
||||
// If we are waiting for more leader keys, swallow the key.
|
||||
info!("Form branch: has_active_seq={}", self.input_engine.has_active_sequence());
|
||||
if self.input_engine.has_active_sequence() {
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
|
||||
@@ -14,12 +14,20 @@ pub struct AuthClient {
|
||||
|
||||
impl AuthClient {
|
||||
pub async fn new() -> Result<Self> {
|
||||
// Kept for backward compatibility; opens a new connection.
|
||||
let client = AuthServiceClient::connect("http://[::1]:50051")
|
||||
.await
|
||||
.context("Failed to connect to auth service")?;
|
||||
Ok(Self { client })
|
||||
}
|
||||
|
||||
/// Preferred: reuse an existing Channel (from GrpcClient).
|
||||
pub async fn with_channel(channel: Channel) -> Result<Self> {
|
||||
Ok(Self {
|
||||
client: AuthServiceClient::new(channel),
|
||||
})
|
||||
}
|
||||
|
||||
/// Login user via gRPC.
|
||||
pub async fn login(&mut self, identifier: String, password: String) -> Result<LoginResponse> {
|
||||
let request = tonic::Request::new(LoginRequest { identifier, password });
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
use common::proto::komp_ac::common::Empty;
|
||||
use common::proto::komp_ac::table_structure::table_structure_service_client::TableStructureServiceClient;
|
||||
use common::proto::komp_ac::table_structure::{GetTableStructureRequest, TableStructureResponse};
|
||||
use common::proto::komp_ac::table_structure::{
|
||||
GetTableStructureRequest, TableStructureResponse,
|
||||
};
|
||||
use common::proto::komp_ac::table_definition::{
|
||||
table_definition_client::TableDefinitionClient,
|
||||
PostTableDefinitionRequest, ProfileTreeResponse, TableDefinitionResponse,
|
||||
@@ -26,11 +28,13 @@ use crate::search::SearchGrpc;
|
||||
use common::proto::komp_ac::search::SearchResponse;
|
||||
use anyhow::{Context, Result};
|
||||
use std::collections::HashMap;
|
||||
use tonic::transport::Channel;
|
||||
use tonic::transport::{Channel, Endpoint};
|
||||
use prost_types::Value;
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GrpcClient {
|
||||
channel: Channel,
|
||||
table_structure_client: TableStructureServiceClient<Channel>,
|
||||
table_definition_client: TableDefinitionClient<Channel>,
|
||||
table_script_client: TableScriptClient<Channel>,
|
||||
@@ -40,7 +44,14 @@ pub struct GrpcClient {
|
||||
|
||||
impl GrpcClient {
|
||||
pub async fn new() -> Result<Self> {
|
||||
let channel = Channel::from_static("http://[::1]:50051")
|
||||
let endpoint = Endpoint::from_static("http://[::1]:50051")
|
||||
.connect_timeout(Duration::from_secs(5))
|
||||
.tcp_keepalive(Some(Duration::from_secs(30)))
|
||||
.keep_alive_while_idle(true)
|
||||
.http2_keep_alive_interval(Duration::from_secs(15))
|
||||
.keep_alive_timeout(Duration::from_secs(5));
|
||||
|
||||
let channel = endpoint
|
||||
.connect()
|
||||
.await
|
||||
.context("Failed to create gRPC channel")?;
|
||||
@@ -54,6 +65,7 @@ impl GrpcClient {
|
||||
let search_client = SearchGrpc::new(channel.clone());
|
||||
|
||||
Ok(Self {
|
||||
channel,
|
||||
table_structure_client,
|
||||
table_definition_client,
|
||||
table_script_client,
|
||||
@@ -62,6 +74,11 @@ impl GrpcClient {
|
||||
})
|
||||
}
|
||||
|
||||
// Expose the shared channel so other typed clients can reuse it.
|
||||
pub fn channel(&self) -> Channel {
|
||||
self.channel.clone()
|
||||
}
|
||||
|
||||
pub async fn get_table_structure(
|
||||
&mut self,
|
||||
profile_name: String,
|
||||
|
||||
@@ -59,7 +59,6 @@ pub struct AppState {
|
||||
pub ui: UiState,
|
||||
|
||||
pub form_editor: HashMap<String, FormEditor<FormState>>, // key = "profile/table"
|
||||
|
||||
#[cfg(feature = "ui-debug")]
|
||||
pub debug_state: Option<DebugState>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user