From 8bf6aff923dfb8f944a2f3ec4eff762c764f926b Mon Sep 17 00:00:00 2001 From: Bartosz Sypytkowski Date: Mon, 24 Jun 2024 11:19:31 +0200 Subject: [PATCH] chore: post rebase fixes --- .../appflowy-collaborate/src/application.rs | 6 ++++++ services/appflowy-collaborate/src/config.rs | 17 +++++++++++++++++ services/appflowy-collaborate/src/state.rs | 2 ++ 3 files changed, 25 insertions(+) diff --git a/services/appflowy-collaborate/src/application.rs b/services/appflowy-collaborate/src/application.rs index 212003d1..4572d856 100644 --- a/services/appflowy-collaborate/src/application.rs +++ b/services/appflowy-collaborate/src/application.rs @@ -14,6 +14,7 @@ use tracing::{info, warn}; use crate::actix_ws::server::RealtimeServerActor; use access_control::access::AccessControl; +use appflowy_ai_client::client::AppFlowyAIClient; use workspace_access::notification::spawn_listen_on_workspace_member_change; use workspace_access::WorkspaceAccessControlImpl; @@ -26,6 +27,7 @@ use crate::collab::notification::spawn_listen_on_collab_member_change; use crate::collab::storage::CollabStorageImpl; use crate::command::{CLCommandReceiver, CLCommandSender}; use crate::config::{Config, DatabaseSetting}; +use crate::indexer::IndexerProvider; use crate::pg_listener::PgListeners; use crate::shared_state::RealtimeSharedState; use crate::snapshot::SnapshotControl; @@ -76,6 +78,7 @@ pub async fn run_actix_server( Duration::from_secs(config.collab.group_persistence_interval_secs), config.collab.edit_state_max_count, config.collab.edit_state_max_secs, + state.indexer_provider.clone(), ) .await .unwrap(); @@ -96,6 +99,8 @@ pub async fn run_actix_server( pub async fn init_state(config: &Config, rt_cmd_tx: CLCommandSender) -> Result { let metrics = AppMetrics::new(); let pg_pool = get_connection_pool(&config.db_settings).await?; + let ai_client = AppFlowyAIClient::new(&config.ai.url()); + let indexer_provider = IndexerProvider::new(pg_pool.clone(), ai_client); // User cache let user_cache = UserCache::new(pg_pool.clone()).await; @@ -154,6 +159,7 @@ pub async fn init_state(config: &Config, rt_cmd_tx: CLCommandSender) -> Result, + pub ai: AISettings, } #[derive(Clone, Debug)] @@ -21,6 +22,18 @@ pub struct ApplicationSetting { pub host: String, } +#[derive(Clone, Debug)] +pub struct AISettings { + pub port: u16, + pub host: String, +} + +impl AISettings { + pub fn url(&self) -> String { + format!("http://{}:{}", self.host, self.port) + } +} + #[derive(Clone, Debug)] pub struct WebsocketSetting { pub heartbeat_interval: u8, @@ -118,6 +131,10 @@ pub fn get_configuration() -> Result { edit_state_max_secs: get_env_var("APPFLOWY_COLLAB_EDIT_STATE_MAX_SECS", "60").parse()?, }, redis_uri: get_env_var("APPFLOWY_REDIS_URI", "redis://localhost:6379").into(), + ai: AISettings { + port: get_env_var("APPFLOWY_AI_SERVER_PORT", "5001").parse()?, + host: get_env_var("APPFLOWY_AI_SERVER_HOST", "localhost"), + }, }; Ok(config) } diff --git a/services/appflowy-collaborate/src/state.rs b/services/appflowy-collaborate/src/state.rs index 2f1a4434..48061224 100644 --- a/services/appflowy-collaborate/src/state.rs +++ b/services/appflowy-collaborate/src/state.rs @@ -12,6 +12,7 @@ use database::user::{select_all_uid_uuid, select_uid_from_uuid}; use crate::collab::storage::CollabAccessControlStorage; use crate::config::Config; +use crate::indexer::IndexerProvider; use crate::metrics::CollabMetrics; use crate::pg_listener::PgListeners; use crate::shared_state::RealtimeSharedState; @@ -29,6 +30,7 @@ pub struct AppState { pub collab_access_control_storage: Arc, pub metrics: AppMetrics, pub realtime_shared_state: RealtimeSharedState, + pub indexer_provider: Arc, } #[derive(Clone)]