Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(search): use read replica database for search queries (#2592)
gbirman367eb083e6f0
diff --git a/infra/stacks/search-processing-service/Pulumi.dev.yaml b/infra/stacks/search-processing-service/Pulumi.dev.yamlindex fa0a4d3789..447c26a0c0 100644--- a/infra/stacks/search-processing-service/Pulumi.dev.yaml+++ b/infra/stacks/search-processing-service/Pulumi.dev.yaml@@ -1,6 +1,6 @@config:aws:region: us-east-1- search-processing-service:database_url_key: macro-db-dev+ search-processing-service:database_url_key: macro-db-readonly-devsearch-processing-service:opensearch_password_key: macro-opensearch-password-devsearch-processing-service:internal_auth_key: document-storage-service-auth-key-devsearch-processing-service:sync_service_auth_key: sync-service-key-devdiff --git a/infra/stacks/search-processing-service/Pulumi.prod.yaml b/infra/stacks/search-processing-service/Pulumi.prod.yamlindex 2765ad6159..255dfcd79b 100644--- a/infra/stacks/search-processing-service/Pulumi.prod.yaml+++ b/infra/stacks/search-processing-service/Pulumi.prod.yaml@@ -1,6 +1,6 @@config:aws:region: us-east-1- search-processing-service:database_url_key: macro-db-prod+ search-processing-service:database_url_key: macro-db-readonly-prodsearch-processing-service:opensearch_password_key: macro-opensearch-password-prodsearch-processing-service:internal_auth_key: document-storage-service-auth-key-prodsearch-processing-service:sync_service_auth_key: sync-service-key-proddiff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex 1cfec71ac2..c0456177f6 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -9495,6 +9495,7 @@ dependencies = ["name_search","opensearch_client","properties_db_client",+ "readonly_pool","secretsmanager_client","serde","serde_json",diff --git a/rust/cloud-storage/document_storage_service/src/api/context.rs b/rust/cloud-storage/document_storage_service/src/api/context.rsindex d1e0f06300..da893e7592 100644--- a/rust/cloud-storage/document_storage_service/src/api/context.rs+++ b/rust/cloud-storage/document_storage_service/src/api/context.rs@@ -45,6 +45,7 @@ use properties::{NotificationServiceImpl, PermissionServiceImpl, PropertiesPgRepo, PropertiesServiceImpl,};use properties_service::PropertiesHandlerState;+use readonly_pool::ReadOnlyPool;use search_service::SearchHandlerState;use secretsmanager_client::LocalOrRemoteSecret;use soup::{@@ -202,6 +203,7 @@ pub(crate) type GithubSyncServiceType =#[derive(Clone, FromRef)]pub(crate) struct ApiContext {pub db: PgPool,+ pub readonly_db: ReadOnlyPool,pub redis_client: Arc<Redis>,pub s3_client: Arc<S3>,pub github_sync_service: Arc<GithubSyncServiceType>,@@ -255,7 +257,7 @@ impl FromRef<ApiContext> for PropertiesHandlerState {impl From<&ApiContext> for SearchHandlerState {fn from(ctx: &ApiContext) -> Self {SearchHandlerState {- db: ctx.db.clone(),+ db: ctx.readonly_db.clone(),opensearch_client: ctx.opensearch_client.clone(),}}diff --git a/rust/cloud-storage/document_storage_service/src/main.rs b/rust/cloud-storage/document_storage_service/src/main.rsindex b86eadf166..18c196e7e2 100644--- a/rust/cloud-storage/document_storage_service/src/main.rs+++ b/rust/cloud-storage/document_storage_service/src/main.rs@@ -439,6 +439,7 @@ async fn main() -> anyhow::Result<()> {),github_sync_service: Arc::new(github_sync_service_impl),db: db.clone(),+ readonly_db: readonly_pool::ReadOnlyPool(readonly_db.clone()),redis_client: Arc::new(Redis::new(redis_client)),s3_client: s3,dynamodb_client: Arc::new(dynamodb_client),diff --git a/rust/cloud-storage/readonly_pool/src/lib.rs b/rust/cloud-storage/readonly_pool/src/lib.rsindex c4c99b9c64..ff53c3febc 100644--- a/rust/cloud-storage/readonly_pool/src/lib.rs+++ b/rust/cloud-storage/readonly_pool/src/lib.rs@@ -4,4 +4,13 @@/// A newtype wrapper around `PgPool` that signals the pool connects to a read-only replica./// Use this instead of a raw `PgPool` in repos that should only perform read queries,/// so it's impossible to accidentally pass a read-write pool.+#[derive(Clone)]pub struct ReadOnlyPool(pub sqlx::PgPool);++impl std::ops::Deref for ReadOnlyPool {+ type Target = sqlx::PgPool;++ fn deref(&self) -> &Self::Target {+ &self.0+ }+}diff --git a/rust/cloud-storage/search_service/Cargo.toml b/rust/cloud-storage/search_service/Cargo.tomlindex 73844af6ff..2acf12dc1f 100644--- a/rust/cloud-storage/search_service/Cargo.toml+++ b/rust/cloud-storage/search_service/Cargo.toml@@ -32,6 +32,7 @@ macro_db_client = { path = "../macro_db_client" }models_properties = { path = "../models_properties" }models_soup = { path = "../models_soup" }properties_db_client = { path = "../properties_db_client" }+readonly_pool = { path = "../readonly_pool" }macro_entrypoint = { path = "../macro_entrypoint" }macro_env = { path = "../macro_env" }macro_middleware = { path = "../macro_middleware", default-features = false, features = [diff --git a/rust/cloud-storage/search_service/src/api/context.rs b/rust/cloud-storage/search_service/src/api/context.rsindex e3dfc49978..096bc9e08c 100644--- a/rust/cloud-storage/search_service/src/api/context.rs+++ b/rust/cloud-storage/search_service/src/api/context.rs@@ -1,14 +1,14 @@use axum::extract::FromRef;use opensearch_client::OpensearchClient;-use sqlx::PgPool;+use readonly_pool::ReadOnlyPool;use std::sync::Arc;/// Minimal state required by search handlers./// This can be extracted from any state that implements `FromRef<SearchHandlerState>`.#[derive(Clone, FromRef)]pub struct SearchHandlerState {- /// Macrodb database connection- pub db: PgPool,+ /// Read-only database connection for search queries+ pub db: ReadOnlyPool,/// OpenSearch client for full-text searchpub opensearch_client: Arc<OpensearchClient>,}