Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(soup): readonly replica support (#2305)

Evan Hutnik62fce46437a4
diff --git a/.env-local.enc b/.env-local.enc
index bcf587d4fc..bc21d987d4 100644
--- a/.env-local.enc
+++ b/.env-local.enc
@@ -16,6 +16,7 @@ CONNECTION_GATEWAY_URL=ENC[AES256_GCM,data:IeVOPf+CgNUcjfjvhUXkiKitTUIs1A9tFU9Vw
CONTACTS_QUEUE=ENC[AES256_GCM,data:wP1F0wjOO+ECsAUTOumYZFJFl9yoa5qBM4zDPYAJFwF53KUblE+eDNBqs0iUucSBro//cQ==,iv:YRS4hUTZOuUYHSpZ6rptZtecnBtDRwrQNaHLp8DtbC8=,tag:/JwRdbS0uFRlo+g1ToW3Ng==,type:str]
CONVERT_QUEUE=ENC[AES256_GCM,data:+GnnxyN6IFH0HBpE+MuoGANoE8s8quNlbYalK3g6QRCp6paDet6ABaTbdft456JM9V4v83c301+2GEU=,iv:5MCIqIOJGHGVPOUfprsRNLlZXMebGtHyJZZ8MG8bGoU=,tag:ber5y8KbPFkmIQnraVOZmg==,type:str]
DATABASE_URL=ENC[AES256_GCM,data:XI5yHcl1gvR4Z1JPdyGoFMjE51nPIk2wihANSf3EQE0+/RyMnP189lJgAOS+Jfsn,iv:zqAD2duv8P8sgDktbrstyzuP+F101Yzs8lhVEa9/wgg=,tag:6kbbm7S7sSPpAaosKurVew==,type:str]
+DATABASE_URL_READONLY=ENC[AES256_GCM,data:pFPXKjXuzEHC51TRkJI9cqKYy3733VCH9bYb6JXQQJd2fWMJ7RDoP3etdgcxwe7M,iv:jFqId0ODmWXYoMFQEcFm4iTqk9UQlz7VlPB9adF4NhE=,tag:E+ZzDet2CIaI14BZu3sV9g==,type:str]
DOCUMENT_COGNITION_SERVICE_URL=ENC[AES256_GCM,data:RabZ2HRhsUdASv/jGUptlBJcKPfdOZd0mtldYJbFljIU8Ycsnxvpww==,iv:gXCnNRm6PZ79P6n5w7vF+3FzGDjjR4TqPd4AARSFJsQ=,tag:GdA7kdv604lO6z15Lzz7KA==,type:str]
DOCUMENT_DELETE_QUEUE=ENC[AES256_GCM,data:MF0RyQYqd1NSwFAdM3Aspu7MIhmX6pfpM15R0YKIq/zcf0NyQFf8q1I+EGT39nxzFTSnXIx3XlsLeKYTVz86tYcb8w==,iv:/7JcBMO0bX8cRNuWhN9pdHbtR0HFbWi0gH/XtNVA78w=,tag:i+Gzwv/e64LKZT4JUdSHFA==,type:str]
DOCUMENT_LIMIT=ENC[AES256_GCM,data:tc/RhbfR,iv:gT1V1tBq/K00a0kfc0G9jRbT4bX5+jDVMk+0pHNUUCE=,tag:01lSMmVZJnw6KuJDArWXSA==,type:str]
@@ -130,7 +131,7 @@ sops_kms__list_1__map_arn=arn:aws:kms:us-west-1:569036502058:key/mrk-cab29bf9480
sops_kms__list_1__map_aws_profile=
sops_kms__list_1__map_created_at=2026-03-03T19:32:07Z
sops_kms__list_1__map_enc=AQICAHjuYcSMsjB0lKJtZ3DIAvxF8N3RNRn5KZaAN74Et6122wFUqf7u/HEfCUGv7j69Mb6YAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMpcJQR1XeIAFFE7ebAgEQgDvYRYIWelwN8TuwA+6fZVaB34yKo9EQ5xPLr/3BU+ro1Mn2eBPCg3q8ie2LuE/3voim1X35P/cdtDqTZg==
-sops_lastmodified=2026-03-30T13:58:29Z
-sops_mac=ENC[AES256_GCM,data:9Z6izAmAPFGthS0T2alA5gydXSlSI4uu6mLq3O14iWadthPQAHSfjxnzErC9ZugvqsbW/wMyNM/KYm6ZZdcwZxU4YqzbtH+OVzr203UULKPA365QPqs07OCWS+Z9NxU9aFlgUpTDdZo/E3TMByqWvLA5yTyruKiDEs4vMEuJxLA=,iv:alTMQAalcWoRR9IwKyzINDo/QpLsOCNZUcZIY8V2340=,tag:czzSXiMvkqERj/fvNVKgkA==,type:str]
+sops_lastmodified=2026-03-30T20:22:37Z
+sops_mac=ENC[AES256_GCM,data:swAKJFY60tRpNkoad2dSqVFVLdV5eu//JT4Yrp1Nv36t/CkxTBRxYxUa5aEgKv2GeiCVjdd+zTX/LANMJRMj5s6stsFH7qNd+5UldvM4qjPeBppLnjyMT5xZaWmovOXsEDCr4TkddDXCFR0L+lZZSmBtpweOAaVZGGX0EBS64x4=,iv:f/znoImRo/tNkpmCTXimuVq6Z9OhnH+zJAy5XviNdEo=,tag:3CeUiXE8Q1lBAZlHuqXUTw==,type:str]
sops_unencrypted_suffix=_unencrypted
sops_version=3.12.1
diff --git a/.env-localdev.enc b/.env-localdev.enc
index fd5635e668..e4b698a456 100644
--- a/.env-localdev.enc
+++ b/.env-localdev.enc
@@ -19,6 +19,7 @@ CONNECTION_GATEWAY_URL=ENC[AES256_GCM,data:W58EUPU5Ffx7aQneJzazq0cntxGX59tORLGSs
CONTACTS_QUEUE=ENC[AES256_GCM,data:nJBeF4xYb9t6BwrQj1syDJp9uG8=,iv:vyIky7/eAAIQLbABxe8pVjW2f24U1phQoIhQBqpYl7U=,tag:XM6JVkLyN34r4mF4ZDEjEg==,type:str]
CONVERT_QUEUE=ENC[AES256_GCM,data:b8FVoOZLZTEuzcJl3MfzSWOgl6gBpdeHJc/n,iv:KibgqkwaUFTuV5z+CR4uX4h7T2isLQI6s3LFebH7ggU=,tag:DDdMNsrICHKxEtmErKE0Jw==,type:str]
DATABASE_URL=ENC[AES256_GCM,data:wczprMkRT0iOZA9iUkKKqvmLIPswcqIXD0g8vZ9sI+SDtCVdhxpC2X7b9g4xGrtlPC7vwmEkgWFHbUUFvFJbPqLeQsvzlsbAhGo7hYXLUw/8ZKJXOPyqSjWCDK0aGJgCzNyQ4kc=,iv:oXanPBy80IxMyHelSrEDoiRuqSYEF2Oasf98+4to2u4=,tag:g8wLjys/+wqWBjTMvwPY2w==,type:str]
+DATABASE_URL_READONLY=ENC[AES256_GCM,data:VlcxMn08cC+trz9dxqTh7HDtGre7eIFzWWgw+43kS5c2YhNo261Tg2nQf6WQm7Q3h2f8DWh7xGNsB6HyHYoj88u2lV/hNgUDlga9p/O00LYxDtKAl/rwTf2tpOUnAgR6HhobhNklgETtl58csoR97Cyu,iv:n5W4ov7P6pEgoqCi6Y1yvnzYCAFS1g/Si/CGn/tgSvM=,tag:UuWQWebnk39oG721aMfc8A==,type:str]
DOCUMENT_COGNITION_SERVICE_URL=ENC[AES256_GCM,data:epUAc5B2oeYabwocWf84EJ977rrd/wHoPkSETgNq6HWfXih9AtTB5g==,iv:Q8g/z1rR3j8LpBMfRjtt75guaSoDUuJk5+sfyQ1WIWg=,tag:3/AyArM08rCiK2tAQWB5FQ==,type:str]
DOCUMENT_DELETE_QUEUE=ENC[AES256_GCM,data:Lp+zaFvMSla8HLemPmIQjFFCL584L5HI2vi7nQypVyJ3szM=,iv:i42V3/x60OMJR3uVCMcmWw5OdIZ0YK1u6T7XR0PDiEw=,tag:cwiV2I4V85sed4bjWdDn9A==,type:str]
DOCUMENT_LIMIT=ENC[AES256_GCM,data:1oF/WNnz,iv:0IfJpl0IQt3ALtCC1hm5fAnGA3eqOu3tCMPCprQDiLs=,tag:cjb0F+gpcHPs1PwMRPiecA==,type:str]
@@ -136,7 +137,7 @@ sops_kms__list_1__map_arn=arn:aws:kms:us-west-1:569036502058:key/mrk-cab29bf9480
sops_kms__list_1__map_aws_profile=
sops_kms__list_1__map_created_at=2026-03-03T19:32:17Z
sops_kms__list_1__map_enc=AQICAHjuYcSMsjB0lKJtZ3DIAvxF8N3RNRn5KZaAN74Et6122wHtcTS4UVhM79Eansn1/OmrAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMRrFwSp99ZM2mPtJzAgEQgDvsIaiNifNz0/18C9OH77AG/LQLpmDiXiJYV46yLDv9vdyPL3PaLMvkAqgL3Xb2F4RcZOIUxkTS3u92xQ==
-sops_lastmodified=2026-03-30T13:58:38Z
-sops_mac=ENC[AES256_GCM,data:Q6uA71fsjnrlWXdbVTgF4gMWrm57ntRzeb81wJUOHEbYqKBGv0NpguzdypanXRucjiJF7yO5z5G7terQ6bhMp4gg19oaFeOKDJ4WY3LjRAKpKqoqIHYIqiTlCr6+NRejdryFN0gOcIVedJDK2mnh3KUtcCXcKa/McD5y/mCe82g=,iv:OmBHduLcGZuVbdIwvjmMJMXKQeQvgXfJPi7ptanJUIQ=,tag:FObrraL4SDOPv0FwXNPTFA==,type:str]
+sops_lastmodified=2026-03-30T20:23:00Z
+sops_mac=ENC[AES256_GCM,data:NQibyHoAMTk42FBQ0brnqcL4KpYZxobK01ooju7gYLN7LY3NT0CjQCSidAqP6QN//QBrjf7Q4SjzOLhwU+EklfwDwLD+dEiRFdPmLYWEesYpvt9/HY+bfdKf4M2Az6TWkzRPnXs+ELbz0Xr6fjC/FBhUzi9LKk4LClBELLmAplc=,iv:pfoH6wTtff6NPcIr7b8Y+w92sFNGEnMTP9HFas+wZIE=,tag:aPrOmqcztN0MxzxhuaAdvA==,type:str]
sops_unencrypted_suffix=_unencrypted
sops_version=3.12.1
diff --git a/infra/stacks/cloud-storage-service/Pulumi.dev.yaml b/infra/stacks/cloud-storage-service/Pulumi.dev.yaml
index cf90674d1f..17d5a90d14 100644
--- a/infra/stacks/cloud-storage-service/Pulumi.dev.yaml
+++ b/infra/stacks/cloud-storage-service/Pulumi.dev.yaml
@@ -3,6 +3,7 @@ config:
aws:region: us-east-1
cloud-storage-service:macro_db_secret_key: macro-db-dev
cloud-storage-service:macro_db_proxy_secret_key: macrodb-rds-proxy-dev
+ cloud-storage-service:macro_db_readonly_secret_key: macro-db-readonly-dev
cloud-storage-service:document_storage_service_auth_key: document-storage-service-auth-key-dev
cloud-storage-service:jwt_secret_key: fusionauth-jwt-secret-dev
cloud-storage-service:fusionauth_client_id: fusionauth-client-id-key-dev
diff --git a/infra/stacks/cloud-storage-service/Pulumi.prod.yaml b/infra/stacks/cloud-storage-service/Pulumi.prod.yaml
index 2bf0a6272e..54cb122d6e 100644
--- a/infra/stacks/cloud-storage-service/Pulumi.prod.yaml
+++ b/infra/stacks/cloud-storage-service/Pulumi.prod.yaml
@@ -3,6 +3,7 @@ config:
aws:region: us-east-1
cloud-storage-service:macro_db_secret_key: macro-db-prod
cloud-storage-service:macro_db_proxy_secret_key: macrodb-rds-proxy-prod
+ cloud-storage-service:macro_db_readonly_secret_key: macro-db-readonly-prod
cloud-storage-service:document_storage_service_auth_key: document-storage-service-auth-key-prod
cloud-storage-service:jwt_secret_key: fusionauth-jwt-secret-prod
cloud-storage-service:fusionauth_client_id: fusionauth-client-id-key-prod
diff --git a/infra/stacks/cloud-storage-service/index.ts b/infra/stacks/cloud-storage-service/index.ts
index 10ad65bd7d..6cf51cec66 100644
--- a/infra/stacks/cloud-storage-service/index.ts
+++ b/infra/stacks/cloud-storage-service/index.ts
@@ -42,6 +42,12 @@ const DATABASE_URL_PROXY = aws.secretsmanager
})
.apply((secret) => secret.secretString);
+const DATABASE_URL_READONLY = aws.secretsmanager
+ .getSecretVersionOutput({
+ secretId: config.require(`macro_db_readonly_secret_key`),
+ })
+ .apply((secret) => secret.secretString);
+
const DOCUMENT_STORAGE_SERVICE_AUTH_KEY = aws.secretsmanager
.getSecretVersionOutput({
secretId: config.get(`document_storage_service_auth_key`) ?? '',
@@ -308,6 +314,10 @@ const cloudStorageService = new CloudStorageService(
name: 'DATABASE_URL',
value: pulumi.interpolate`${DATABASE_URL}`,
},
+ {
+ name: 'DATABASE_URL_READONLY',
+ value: pulumi.interpolate`${DATABASE_URL_READONLY}`,
+ },
{
name: 'REDIS_URI',
value: pulumi.interpolate`redis://${MACRO_CACHE}`,
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 10b1b6c94e..f66ba9bacc 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -1966,6 +1966,7 @@ dependencies = [
"model_user",
"models_comms",
"models_pagination",
+ "readonly_pool",
"recursion",
"rootcause",
"serde",
@@ -2928,6 +2929,7 @@ dependencies = [
"models_permissions",
"notification",
"properties",
+ "readonly_pool",
"redis",
"regex",
"reqwest",
@@ -3047,6 +3049,7 @@ dependencies = [
"properties_db_client",
"properties_service",
"rayon",
+ "readonly_pool",
"redis",
"regex",
"reqwest",
@@ -6131,6 +6134,7 @@ dependencies = [
"macro_uuid",
"model_user",
"properties",
+ "readonly_pool",
"scribe",
"search_service_client",
"serde",
@@ -8051,6 +8055,13 @@ dependencies = [
"crossbeam-utils",
]
+[[package]]
+name = "readonly_pool"
+version = "0.1.0"
+dependencies = [
+ "sqlx",
+]
+
[[package]]
name = "recursion"
version = "0.5.4"
@@ -9527,6 +9538,7 @@ dependencies = [
"non_empty",
"ordered-float",
"properties_db_client",
+ "readonly_pool",
"recursion",
"rootcause",
"schemars",
diff --git a/rust/cloud-storage/Cargo.toml b/rust/cloud-storage/Cargo.toml
index 8b42b05288..9b9582d08e 100644
--- a/rust/cloud-storage/Cargo.toml
+++ b/rust/cloud-storage/Cargo.toml
@@ -98,6 +98,7 @@ members = [
"properties_db_client",
"properties_service",
"rate_limit",
+ "readonly_pool",
"referral",
"invite_email",
"roles_and_permissions",
diff --git a/rust/cloud-storage/ai_tools/src/tool_context.rs b/rust/cloud-storage/ai_tools/src/tool_context.rs
index 78f52029f9..8f0e7e8b5b 100644
--- a/rust/cloud-storage/ai_tools/src/tool_context.rs
+++ b/rust/cloud-storage/ai_tools/src/tool_context.rs
@@ -9,7 +9,10 @@ use documents::{
inbound::toolset::DocumentToolContext,
outbound::{pg_document_repo::PgDocumentRepo, s3_upload_url::S3UploadUrlAdapter},
};
-use email::{domain::service::EmailServiceImpl, outbound::EmailPgRepo};
+use email::{
+ domain::{ports::ReadonlyEmailPreviewAdapter, service::EmailServiceImpl},
+ outbound::EmailPgRepo,
+};
use entity_access::{domain::service::EntityAccessServiceImpl, outbound::PgAccessRepository};
use frecency::{domain::services::FrecencyQueryServiceImpl, outbound::postgres::FrecencyPgStorage};
use properties::inbound::toolset::PropertiesToolContext;
@@ -93,8 +96,12 @@ pub type ToolDocumentToolContext =
DocumentToolContext<ToolDocumentService, ToolEntityAccessService>;
/// Type alias for the soup service implementation
-pub type ToolSoupService =
- SoupImpl<PgSoupRepo, ToolFrecencyService, ToolEmailService, ToolCommsService>;
+pub type ToolSoupService = SoupImpl<
+ PgSoupRepo,
+ ToolFrecencyService,
+ ReadonlyEmailPreviewAdapter<ToolEmailService>,
+ ToolCommsService,
+>;
/// No-op notification service for properties (tools don't send assignment notifications)
#[derive(Clone)]
diff --git a/rust/cloud-storage/comms/Cargo.toml b/rust/cloud-storage/comms/Cargo.toml
index e4b3145456..3690a80b5d 100644
--- a/rust/cloud-storage/comms/Cargo.toml
+++ b/rust/cloud-storage/comms/Cargo.toml
@@ -6,7 +6,7 @@ version = "0.1.0"
[features]
inbound = ["dep:axum", "dep:model_user", "dep:utoipa"]
-outbound = ["dep:sqlx"]
+outbound = ["dep:readonly_pool", "dep:sqlx"]
[dependencies]
@@ -21,6 +21,7 @@ model-entity = { path = "../model-entity" }
model_user = { path = "../model_user", optional = true, features = ["axum"] }
models_comms = { path = "../models_comms" }
models_pagination = { path = "../models_pagination" }
+readonly_pool = { path = "../readonly_pool", optional = true }
recursion = { workspace = true }
rootcause = { workspace = true }
serde = { workspace = true }
diff --git a/rust/cloud-storage/comms/src/outbound/postgres/comms_repo.rs b/rust/cloud-storage/comms/src/outbound/postgres/comms_repo.rs
index 22cc76ed65..2b8bab9572 100644
--- a/rust/cloud-storage/comms/src/outbound/postgres/comms_repo.rs
+++ b/rust/cloud-storage/comms/src/outbound/postgres/comms_repo.rs
@@ -319,7 +319,13 @@ pub async fn get_activities(
}
pub struct PgCommsRepo {
- pub pool: PgPool,
+ pool: readonly_pool::ReadOnlyPool,
+}
+
+impl PgCommsRepo {
+ pub fn new(pool: readonly_pool::ReadOnlyPool) -> Self {
+ Self { pool }
+ }
}
impl CommsRepo for PgCommsRepo {
@@ -327,7 +333,7 @@ impl CommsRepo for PgCommsRepo {
&self,
req: GetChannelsParams,
) -> Result<Vec<ChannelWithParticipants>, rootcause::Report> {
- Ok(get_user_channels_dynamic(&self.pool, &req).await?)
+ Ok(get_user_channels_dynamic(&self.pool.0, &req).await?)
}
async fn get_latest_channel_messages_batch(
@@ -337,13 +343,13 @@ impl CommsRepo for PgCommsRepo {
std::collections::HashMap<ChannelId, models_comms::channel::LatestMessage>,
rootcause::Report,
> {
- get_latest_channel_messages_batch(&self.pool, channels).await
+ get_latest_channel_messages_batch(&self.pool.0, channels).await
}
async fn get_activities(
&self,
user_id: MacroUserIdStr<'_>,
) -> Result<Vec<models_comms::channel::Activity>, rootcause::Report> {
- get_activities(&self.pool, user_id).await
+ get_activities(&self.pool.0, user_id).await
}
}
diff --git a/rust/cloud-storage/document_cognition_service/Cargo.toml b/rust/cloud-storage/document_cognition_service/Cargo.toml
index f870b250a4..6f0d472d33 100644
--- a/rust/cloud-storage/document_cognition_service/Cargo.toml
+++ b/rust/cloud-storage/document_cognition_service/Cargo.toml
@@ -112,6 +112,7 @@ secretsmanager_client = { path = "../secretsmanager_client" }
serde = { workspace = true }
serde_json = { workspace = true }
sha2 = { workspace = true }
+readonly_pool = { path = "../readonly_pool" }
soup = { path = "../soup", features = ["outbound"] }
sqlx = { workspace = true }
sqs_client = { path = "../sqs_client", default-features = false, features = [
diff --git a/rust/cloud-storage/document_cognition_service/src/api/context/test.rs b/rust/cloud-storage/document_cognition_service/src/api/context/test.rs
index 1ccdbea73f..d72f60f73e 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/context/test.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/context/test.rs
@@ -114,6 +114,7 @@ pub async fn test_api_context(pool: sqlx::Pool<sqlx::Postgres>) -> std::sync::Ar
use comms_service_client::CommsServiceClient;
use document_cognition_service_client::DocumentCognitionServiceClient;
use document_storage_service_client::DocumentStorageServiceClient;
+ use email::domain::ports::ReadonlyEmailPreviewAdapter;
use email::domain::service::EmailServiceImpl;
use email::outbound::EmailPgRepo;
use email_service_client::{EmailServiceClient, EmailServiceClientExternal};
@@ -194,14 +195,14 @@ pub async fn test_api_context(pool: sqlx::Pool<sqlx::Postgres>) -> std::sync::Ar
);
let user_repo = PgUserRepo::new(pool.clone());
let channels_service = ChannelServiceImpl::new(
- PgCommsRepo { pool: pool.clone() },
+ PgCommsRepo::new(readonly_pool::ReadOnlyPool(pool.clone())),
user_repo,
frecency_storage,
);
let soup_service = Arc::new(SoupImpl::new(
- PgSoupRepo::new(pool.clone()),
+ PgSoupRepo::new(readonly_pool::ReadOnlyPool(pool.clone())),
frecency_service,
- email_service,
+ ReadonlyEmailPreviewAdapter(email_service),
channels_service,
));
diff --git a/rust/cloud-storage/document_cognition_service/src/bin/mcp_server.rs b/rust/cloud-storage/document_cognition_service/src/bin/mcp_server.rs
index b1b6661e7f..0e0544a9f4 100644
--- a/rust/cloud-storage/document_cognition_service/src/bin/mcp_server.rs
+++ b/rust/cloud-storage/document_cognition_service/src/bin/mcp_server.rs
@@ -21,6 +21,7 @@ use documents::{
inbound::toolset::DocumentToolContext,
outbound::{pg_document_repo::PgDocumentRepo, s3_upload_url::S3UploadUrlAdapter},
};
+use email::domain::ports::ReadonlyEmailPreviewAdapter;
use email::domain::service::EmailServiceImpl;
use email::outbound::EmailPgRepo;
use email_service_client::{EmailServiceClient, EmailServiceClientExternal};
@@ -160,14 +161,14 @@ async fn main() -> anyhow::Result<()> {
0,
);
let channels_service = ChannelServiceImpl::new(
- PgCommsRepo { pool: db.clone() },
+ PgCommsRepo::new(readonly_pool::ReadOnlyPool(db.clone())),
PgUserRepo::new(db.clone()),
frecency_storage,
);
let soup_service = Arc::new(SoupImpl::new(
- PgSoupRepo::new(db.clone()),
+ PgSoupRepo::new(readonly_pool::ReadOnlyPool(db.clone())),
frecency_service,
- email_service,
+ ReadonlyEmailPreviewAdapter(email_service),
channels_service,
));
diff --git a/rust/cloud-storage/document_cognition_service/src/main.rs b/rust/cloud-storage/document_cognition_service/src/main.rs
index 0080b51d08..fee908aede 100644
--- a/rust/cloud-storage/document_cognition_service/src/main.rs
+++ b/rust/cloud-storage/document_cognition_service/src/main.rs
@@ -13,6 +13,7 @@ use documents::{
inbound::toolset::DocumentToolContext,
outbound::{pg_document_repo::PgDocumentRepo, s3_upload_url::S3UploadUrlAdapter},
};
+use email::domain::ports::ReadonlyEmailPreviewAdapter;
use email::domain::service::EmailServiceImpl;
use email::outbound::EmailPgRepo;
use email_service_client::{EmailServiceClient, EmailServiceClientExternal};
@@ -153,14 +154,14 @@ async fn main() -> anyhow::Result<()> {
0,
);
let channels_service = ChannelServiceImpl::new(
- PgCommsRepo { pool: db.clone() },
+ PgCommsRepo::new(readonly_pool::ReadOnlyPool(db.clone())),
PgUserRepo::new(db.clone()),
frecency_storage,
);
let soup_service = Arc::new(SoupImpl::new(
- PgSoupRepo::new(db.clone()),
+ PgSoupRepo::new(readonly_pool::ReadOnlyPool(db.clone())),
frecency_service,
- email_service,
+ ReadonlyEmailPreviewAdapter(email_service),
channels_service,
));
diff --git a/rust/cloud-storage/document_storage_service/Cargo.toml b/rust/cloud-storage/document_storage_service/Cargo.toml
index 6848f69be2..cd3e5fbdcf 100644
--- a/rust/cloud-storage/document_storage_service/Cargo.toml
+++ b/rust/cloud-storage/document_storage_service/Cargo.toml
@@ -117,6 +117,7 @@ reqwest = { workspace = true }
saved_views = { path = "../saved_views" }
schemars = { workspace = true }
search_service = { path = "../search_service" }
+readonly_pool = { path = "../readonly_pool" }
secretsmanager_client = { path = "../secretsmanager_client" }
serde = { workspace = true }
serde_json = { workspace = true }
diff --git a/rust/cloud-storage/document_storage_service/src/api/context.rs b/rust/cloud-storage/document_storage_service/src/api/context.rs
index cf6441ee05..b4283d08f9 100644
--- a/rust/cloud-storage/document_storage_service/src/api/context.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/context.rs
@@ -21,7 +21,10 @@ use documents_hex::inbound::axum_router::DocumentRouterState;
use documents_hex::outbound::pg_document_repo::PgDocumentRepo;
use documents_hex::outbound::s3_upload_url::S3UploadUrlAdapter;
use dynamodb_client::DynamodbClient;
-use email::{domain::service::EmailServiceImpl, outbound::EmailPgRepo};
+use email::{
+ domain::{ports::ReadonlyEmailPreviewAdapter, service::EmailServiceImpl},
+ outbound::EmailPgRepo,
+};
use entity_access::{domain::service::EntityAccessServiceImpl, outbound::PgAccessRepository};
use frecency::{domain::services::FrecencyQueryServiceImpl, outbound::postgres::FrecencyPgStorage};
use github::domain::service::GithubSyncServiceImpl;
@@ -56,24 +59,21 @@ pub struct InternalFlag {
pub internal: bool,
}
+type DssEmailService = EmailServiceImpl<
+ EmailPgRepo,
+ FrecencyQueryServiceImpl<FrecencyPgStorage>,
+ email::domain::ports::NoOpEnqueuer,
+ email::domain::ports::NoOpGmailLabelModifier,
+>;
+
type DssSoupState = SoupRouterState<
SoupImpl<
PgSoupRepo,
FrecencyQueryServiceImpl<FrecencyPgStorage>,
- EmailServiceImpl<
- EmailPgRepo,
- FrecencyQueryServiceImpl<FrecencyPgStorage>,
- email::domain::ports::NoOpEnqueuer,
- email::domain::ports::NoOpGmailLabelModifier,
- >,
+ ReadonlyEmailPreviewAdapter<DssEmailService>,
ChannelServiceImpl<PgCommsRepo, PgUserRepo, FrecencyPgStorage>,
>,
- EmailServiceImpl<
- EmailPgRepo,
- FrecencyQueryServiceImpl<FrecencyPgStorage>,
- email::domain::ports::NoOpEnqueuer,
- email::domain::ports::NoOpGmailLabelModifier,
- >,
+ DssEmailService,
>;
type SystemPropertiesService = SystemPropertiesServiceImpl<PgSystemPropertiesRepository>;
diff --git a/rust/cloud-storage/document_storage_service/src/config.rs b/rust/cloud-storage/document_storage_service/src/config.rs
index 9d5de7f8d1..f74e49809f 100644
--- a/rust/cloud-storage/document_storage_service/src/config.rs
+++ b/rust/cloud-storage/document_storage_service/src/config.rs
@@ -39,6 +39,7 @@ pub struct Config {
env_var! {
struct EnvVars {
pub DatabaseUrl,
+ pub DatabaseUrlReadonly,
pub DocumentStorageBucket,
pub DocxDocumentUploadBucket,
pub DocumentDeleteQueue,
diff --git a/rust/cloud-storage/document_storage_service/src/main.rs b/rust/cloud-storage/document_storage_service/src/main.rs
index fc4832faed..b18f85ff71 100644
--- a/rust/cloud-storage/document_storage_service/src/main.rs
+++ b/rust/cloud-storage/document_storage_service/src/main.rs
@@ -29,7 +29,10 @@ use documents_hex::inbound::axum_router::DocumentRouterState;
use documents_hex::outbound::pg_document_repo::PgDocumentRepo;
use documents_hex::outbound::s3_upload_url::S3UploadUrlAdapter;
use dynamodb_client::DynamodbClient;
-use email::{domain::service::EmailServiceImpl, outbound::EmailPgRepo};
+use email::{
+ domain::{ports::ReadonlyEmailPreviewAdapter, service::EmailServiceImpl},
+ outbound::EmailPgRepo,
+};
use frecency::{domain::services::FrecencyQueryServiceImpl, outbound::postgres::FrecencyPgStorage};
use github::domain::service::{GithubSyncConfig, GithubSyncServiceImpl};
use github::outbound::github_sync_client::GithubSyncClientImpl;
@@ -114,6 +117,22 @@ async fn main() -> anyhow::Result<()> {
"initialized db connection"
);
+ let readonly_db = match PgPoolOptions::new()
+ .min_connections(min_connections)
+ .max_connections(max_connections)
+ .connect(&config.vars.database_url_readonly)
+ .await
+ {
+ Ok(pool) => {
+ tracing::trace!("initialized readonly db connection");
+ pool
+ }
+ Err(e) => {
+ tracing::warn!(error=?e, "failed to connect to readonly db, falling back to primary");
+ db.clone()
+ }
+ };
+
let dynamo_db = aws_sdk_dynamodb::Client::new(&aws_config);
let dynamodb_client = DynamodbClient::new_from_client(
@@ -208,6 +227,13 @@ async fn main() -> anyhow::Result<()> {
email::domain::ports::NoOpGmailLabelModifier,
0,
);
+ let readonly_email_service = ReadonlyEmailPreviewAdapter(EmailServiceImpl::new(
+ EmailPgRepo::new(readonly_db.clone()),
+ frecency_service.clone(),
+ email::domain::ports::NoOpEnqueuer,
+ email::domain::ports::NoOpGmailLabelModifier,
+ 0,
+ ));
let system_properties_service =
SystemPropertiesServiceImpl::new(PgSystemPropertiesRepository::new(db.clone()));
let ingress_queue = SqsIngressQueue {
@@ -231,12 +257,12 @@ async fn main() -> anyhow::Result<()> {
// Create the ChannelServiceImpl - we need to create separate instances as it doesn't impl Clone
let channel_service_for_soup = ChannelServiceImpl::new(
- PgCommsRepo { pool: db.clone() },
- PgUserRepo::new(db.clone()),
+ PgCommsRepo::new(readonly_pool::ReadOnlyPool(readonly_db.clone())),
+ PgUserRepo::new(readonly_db.clone()),
frecency_storage.clone(),
);
let channel_service_for_comms = ChannelServiceImpl::new(
- PgCommsRepo { pool: db.clone() },
+ PgCommsRepo::new(readonly_pool::ReadOnlyPool(db.clone())),
PgUserRepo::new(db.clone()),
frecency_storage.clone(),
);
@@ -332,9 +358,9 @@ async fn main() -> anyhow::Result<()> {
let api_context = ApiContext {
soup_router_state: SoupRouterState::new(
SoupImpl::new(
- PgSoupRepo::new(db.clone()),
+ PgSoupRepo::new(readonly_pool::ReadOnlyPool(readonly_db.clone())),
frecency_service,
- email_service.clone(),
+ readonly_email_service,
channel_service_for_soup,
),
email_service,
diff --git a/rust/cloud-storage/email/src/domain/ports.rs b/rust/cloud-storage/email/src/domain/ports.rs
index 6419b20c41..9cf088021a 100644
--- a/rust/cloud-storage/email/src/domain/ports.rs
+++ b/rust/cloud-storage/email/src/domain/ports.rs
@@ -250,6 +250,39 @@ pub trait EmailRepo: Send + Sync + 'static {
) -> impl Future<Output = Result<Vec<EmailFilter>, Self::Err>> + Send;
}
+/// Read-only trait for fetching email thread previews.
+/// Used by soup to restrict access to only read email operations as it uses the read replica database.
+pub trait EmailPreviewServiceReadOnly: Send + Sync + 'static {
+ fn get_email_thread_previews(
+ &self,
+ req: GetEmailsRequest,
+ ) -> impl Future<
+ Output = Result<
+ PaginatedCursor<EnrichedEmailThreadPreview, Uuid, SimpleSortMethod, ()>,
+ EmailErr,
+ >,
+ > + Send;
+}
+
+/// Newtype adapter that restricts a full `EmailService` to read-only preview access.
+/// Wrapping is explicit so readonly wiring is intentional — a bare `EmailServiceImpl`
+/// will *not* silently satisfy `EmailPreviewServiceReadOnly`.
+pub struct ReadonlyEmailPreviewAdapter<T>(pub T);
+
+impl<T: EmailService> EmailPreviewServiceReadOnly for ReadonlyEmailPreviewAdapter<T> {
+ fn get_email_thread_previews(
+ &self,
+ req: GetEmailsRequest,
+ ) -> impl Future<
+ Output = Result<
+ PaginatedCursor<EnrichedEmailThreadPreview, Uuid, SimpleSortMethod, ()>,
+ EmailErr,
+ >,
+ > + Send {
+ EmailService::get_email_thread_previews(&self.0, req)
+ }
+}
+
pub trait EmailService: Send + Sync + 'static {
fn get_email_thread_previews(
&self,
diff --git a/rust/cloud-storage/memory/Cargo.toml b/rust/cloud-storage/memory/Cargo.toml
index 86ce83fb0f..9aa1ae46d5 100644
--- a/rust/cloud-storage/memory/Cargo.toml
+++ b/rust/cloud-storage/memory/Cargo.toml
@@ -38,6 +38,7 @@ email_service_client = { path = "../email_service_client" }
document_storage_service_client = { path = "../document_storage_service_client" }
static_file_service_client = { path = "../static_file_service_client" }
sync_service_client = { path = "../sync_service_client" }
+readonly_pool = { path = "../readonly_pool" }
soup = { path = "../soup", features = ["all"] }
properties = { path = "../properties" }
macro_aws_config = { path = "../macro_aws_config" }
diff --git a/rust/cloud-storage/memory/src/context.rs b/rust/cloud-storage/memory/src/context.rs
index b374181ac9..915a5dcbac 100644
--- a/rust/cloud-storage/memory/src/context.rs
+++ b/rust/cloud-storage/memory/src/context.rs
@@ -9,6 +9,7 @@ use documents::domain::models::CloudFrontConfig;
use documents::inbound::toolset::DocumentToolContext;
use documents::outbound::pg_document_repo::PgDocumentRepo;
use documents::outbound::s3_upload_url::S3UploadUrlAdapter;
+use email::domain::ports::ReadonlyEmailPreviewAdapter;
use email::domain::service::EmailServiceImpl;
use email::outbound::EmailPgRepo;
use email_service_client::{EmailServiceClient, EmailServiceClientExternal};
@@ -102,14 +103,14 @@ pub async fn build_tool_service_context(pool: sqlx::PgPool) -> anyhow::Result<To
0,
);
let channels_service = ChannelServiceImpl::new(
- PgCommsRepo { pool: pool.clone() },
+ PgCommsRepo::new(readonly_pool::ReadOnlyPool(pool.clone())),
PgUserRepo::new(pool.clone()),
frecency_storage,
);
let soup_service = Arc::new(SoupImpl::new(
- PgSoupRepo::new(pool.clone()),
+ PgSoupRepo::new(readonly_pool::ReadOnlyPool(pool.clone())),
frecency_service,
- email_service,
+ ReadonlyEmailPreviewAdapter(email_service),
channels_service,
));
diff --git a/rust/cloud-storage/readonly_pool/Cargo.toml b/rust/cloud-storage/readonly_pool/Cargo.toml
new file mode 100644
index 0000000000..72d454416f
--- /dev/null
+++ b/rust/cloud-storage/readonly_pool/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+edition = "2024"
+name = "readonly_pool"
+publish = false
+version = "0.1.0"
+
+[dependencies]
+sqlx = { workspace = true }
diff --git a/rust/cloud-storage/readonly_pool/src/lib.rs b/rust/cloud-storage/readonly_pool/src/lib.rs
new file mode 100644
index 0000000000..c4c99b9c64
--- /dev/null
+++ b/rust/cloud-storage/readonly_pool/src/lib.rs
@@ -0,0 +1,7 @@
+#![deny(missing_docs)]
+//! Type-safe wrapper for read-only database pool connections.
+
+/// 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.
+pub struct ReadOnlyPool(pub sqlx::PgPool);
diff --git a/rust/cloud-storage/soup/Cargo.toml b/rust/cloud-storage/soup/Cargo.toml
index d8e7423dd0..014baf4702 100644
--- a/rust/cloud-storage/soup/Cargo.toml
+++ b/rust/cloud-storage/soup/Cargo.toml
@@ -30,7 +30,7 @@ axum = [
"models_soup/schema",
]
inbound = ["email/inbound", "ports"]
-outbound = ["dep:sqlx", "ports"]
+outbound = ["dep:readonly_pool", "dep:sqlx", "ports"]
ports = ["dep:tokio", "frecency/ports"]
@@ -59,6 +59,7 @@ models_properties = { path = "../models_properties" }
models_soup = { path = "../models_soup" }
non_empty = { path = "../non_empty" }
properties_db_client = { path = "../properties_db_client/" }
+readonly_pool = { path = "../readonly_pool", optional = true }
recursion = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true }
diff --git a/rust/cloud-storage/soup/examples/ai_tools_cli.rs b/rust/cloud-storage/soup/examples/ai_tools_cli.rs
index 72f535e416..faa9b9567c 100644
--- a/rust/cloud-storage/soup/examples/ai_tools_cli.rs
+++ b/rust/cloud-storage/soup/examples/ai_tools_cli.rs
@@ -18,6 +18,7 @@ use ai::types::Model;
use comms::domain::service::ChannelServiceImpl;
use comms::outbound::postgres::comms_repo::PgCommsRepo;
use comms::outbound::postgres::user_repo::PgUserRepo;
+use email::domain::ports::ReadonlyEmailPreviewAdapter;
use email::domain::service::EmailServiceImpl;
use email::outbound::EmailPgRepo;
use frecency::domain::services::FrecencyQueryServiceImpl;
@@ -59,13 +60,18 @@ async fn main() {
);
// Create the channels service with real database connections
- let comms_repo = PgCommsRepo { pool: pool.clone() };
+ let comms_repo = PgCommsRepo::new(readonly_pool::ReadOnlyPool(pool.clone()));
let user_repo = PgUserRepo::new(pool.clone());
let channels_service = ChannelServiceImpl::new(comms_repo, user_repo, frecency_storage);
// Create the soup service with real database connections
- let soup_repo = PgSoupRepo::new(pool);
- let soup_service = SoupImpl::new(soup_repo, frecency_service, email_service, channels_service);
+ let soup_repo = PgSoupRepo::new(readonly_pool::ReadOnlyPool(pool));
+ let soup_service = SoupImpl::new(
+ soup_repo,
+ frecency_service,
+ ReadonlyEmailPreviewAdapter(email_service),
+ channels_service,
+ );
// Create the soup tool context
let soup_context = SoupToolContext::new(soup_service);
diff --git a/rust/cloud-storage/soup/src/domain/service.rs b/rust/cloud-storage/soup/src/domain/service.rs
index 27ea07a553..7a62d6d43d 100644
--- a/rust/cloud-storage/soup/src/domain/service.rs
+++ b/rust/cloud-storage/soup/src/domain/service.rs
@@ -11,7 +11,7 @@ use doppleganger::Mirror;
use either::Either;
use email::domain::{
models::{EnrichedEmailThreadPreview, GetEmailsRequest},
- ports::EmailService,
+ ports::EmailPreviewServiceReadOnly,
};
use frecency::domain::{
models::{AggregateId, FrecencyPageRequest, JoinFrecency},
@@ -54,7 +54,7 @@ where
T: SoupRepo,
anyhow::Error: From<T::Err>,
U: FrecencyQueryService,
- V: EmailService,
+ V: EmailPreviewServiceReadOnly,
C: ChannelsService,
{
pub fn new(soup_storage: T, frecency: U, email_service: V, comms_service: C) -> Self {
@@ -349,7 +349,7 @@ where
T: SoupRepo,
anyhow::Error: From<T::Err>,
U: FrecencyQueryService,
- V: EmailService,
+ V: EmailPreviewServiceReadOnly,
C: ChannelsService,
{
#[tracing::instrument(err, skip(self, req))]
diff --git a/rust/cloud-storage/soup/src/domain/service/tests.rs b/rust/cloud-storage/soup/src/domain/service/tests.rs
index 3c037f2232..9872483cab 100644
--- a/rust/cloud-storage/soup/src/domain/service/tests.rs
+++ b/rust/cloud-storage/soup/src/domain/service/tests.rs
@@ -3,8 +3,7 @@ use crate::domain::ports::MockSoupRepo;
use chrono::Days;
use comms::domain::models::GetChannelsRequest;
use cool_asserts::assert_matches;
-use email::domain::models::{EmailErr, EnrichedEmailThreadPreview, PreviewView};
-use entity_access::domain::models::{EntityAccessReceipt, ViewAccessLevel};
+use email::domain::models::{EnrichedEmailThreadPreview, PreviewView};
use frecency::domain::models::{FrecencyPageRequest, FrecencyPageResponse};
use frecency::domain::ports::MockFrecencyQueryService;
use frecency::domain::services::FrecencyQueryServiceImpl;
@@ -23,9 +22,9 @@ use uuid::Uuid;
use super::*;
-struct NoopEmailService;
+struct NoopEmailPreviewService;
-impl EmailService for NoopEmailService {
+impl EmailPreviewServiceReadOnly for NoopEmailPreviewService {
async fn get_email_thread_previews(
&self,
_req: email::domain::models::GetEmailsRequest,
@@ -38,106 +37,6 @@ impl EmailService for NoopEmailService {
.paginate_on(0, SimpleSortMethod::CreatedAt)
.into_page())
}
-
- async fn get_link_by_auth_id_and_macro_id(
- &self,
- _auth_id: &str,
- _macro_id: MacroUserIdStr<'_>,
- ) -> Result<Option<email::domain::models::Link>, email::domain::models::EmailErr> {
- Err(EmailErr::RepoErr(anyhow::anyhow!("not implemented")))
- }
-
- async fn get_link_by_macro_id(
- &self,
- _macro_id: MacroUserIdStr<'_>,
- ) -> Result<Option<email::domain::models::Link>, email::domain::models::EmailErr> {
- Err(EmailErr::RepoErr(anyhow::anyhow!("not implemented")))
- }
-
- async fn get_thread_with_messages(
- &self,
- _receipt: EntityAccessReceipt<ViewAccessLevel>,
- _offset: i64,
- _limit: i64,
- ) -> Result<Option<email::domain::models::Thread>, EmailErr> {
- Err(EmailErr::RepoErr(anyhow::anyhow!("not implemented")))
- }
-
- async fn get_thread_parsed(
- &self,
- _receipt: EntityAccessReceipt<ViewAccessLevel>,
- _offset: i64,
- _limit: i64,
- ) -> Result<Option<email::domain::models::ParsedThread>, EmailErr> {
- Err(EmailErr::RepoErr(anyhow::anyhow!("not implemented")))
- }
-
- async fn create_draft(
- &self,
- _link: &email::domain::models::Link,
- _input: email::domain::models::CreateDraftInput,
- ) -> Result<email::domain::models::CreatedDraft, EmailErr> {
- Err(EmailErr::RepoErr(anyhow::anyhow!("not implemented")))
- }
-
- async fn send_message(
- &self,
- _link: &email::domain::models::Link,
- _input: email::domain::models::CreateDraftInput,
- ) -> Result<email::domain::models::CreatedDraft, EmailErr> {
- Err(EmailErr::RepoErr(anyhow::anyhow!("not implemented")))
- }
-
- async fn list_labels(
- &self,
- _link: &email::domain::models::Link,
- ) -> Result<Vec<email::domain::models::LinkLabel>, EmailErr> {
- Err(EmailErr::RepoErr(anyhow::anyhow!("not implemented")))
- }
-
- async fn update_thread_labels(
- &self,
- _access_token: &str,
- _link: &email::domain::models::Link,
- _thread_id: uuid::Uuid,
- _label_id: uuid::Uuid,
- _add: bool,
- ) -> Result<email::domain::models::UpdateThreadLabelsResult, EmailErr> {
- Err(EmailErr::RepoErr(anyhow::anyhow!("not implemented")))
- }
-
- async fn update_thread_project(
- &self,
- _thread_receipt: EntityAccessReceipt<entity_access::domain::models::EditAccessLevel>,
- _project_receipt: Option<
- EntityAccessReceipt<entity_access::domain::models::EditAccessLevel>,
- >,
- ) -> Result<Option<String>, EmailErr> {
- Err(EmailErr::RepoErr(anyhow::anyhow!("not implemented")))
- }
-
- async fn upsert_email_filter(
- &self,
- _link: &email::domain::models::Link,
- _input: email::domain::models::UpsertEmailFilterInput,
- ) -> Result<email::domain::models::EmailFilter, EmailErr> {
- Err(EmailErr::RepoErr(anyhow::anyhow!("not implemented")))
- }
-
- async fn delete_email_filter(
- &self,
- _link: &email::domain::models::Link,
- _filter_id: Uuid,
- ) -> Result<bool, EmailErr> {
- Err(EmailErr::RepoErr(anyhow::anyhow!("not implemented")))
- }
-
- async fn list_email_filters(
- &self,
- _link: &email::domain::models::Link,
- ) -> Result<Vec<email::domain::models::EmailFilter>, EmailErr> {
- Err(EmailErr::RepoErr(anyhow::anyhow!("not implemented")))
- }
}
struct NoopCommsService;
@@ -261,7 +160,7 @@ async fn it_should_not_query_frecency() {
let res = SoupImpl::new(
soup_mock,
FrecencyQueryServiceImpl::new(MockFrecencyStorage::new()),
- NoopEmailService,
+ NoopEmailPreviewService,
NoopCommsService,
)
.get_user_soup(SoupRequest {
@@ -342,7 +241,7 @@ async fn it_should_query_frecency() {
let res = SoupImpl::new(
soup_mock,
FrecencyQueryServiceImpl::new(frecency_mock),
- NoopEmailService,
+ NoopEmailPreviewService,
NoopCommsService,
)
.get_user_soup(SoupRequest {
@@ -420,7 +319,7 @@ async fn it_should_sort_frecency_descending() {
let res = SoupImpl::new(
soup_mock,
FrecencyQueryServiceImpl::new(frecency_mock),
- NoopEmailService,
+ NoopEmailPreviewService,
NoopCommsService,
)
.get_user_soup(SoupRequest {
@@ -509,7 +408,7 @@ async fn frecency_should_fallback() {
Box::pin(async move { res })
});
- let res = SoupImpl::new(soup, frecency, NoopEmailService, NoopCommsService)
+ let res = SoupImpl::new(soup, frecency, NoopEmailPreviewService, NoopCommsService)
.get_user_soup(SoupRequest {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
@@ -580,7 +479,7 @@ async fn frecency_should_paginate() {
Box::pin(async move { Ok(vec) })
});
- let res = SoupImpl::new(soup, frecency, NoopEmailService, NoopCommsService)
+ let res = SoupImpl::new(soup, frecency, NoopEmailPreviewService, NoopCommsService)
.get_user_soup(SoupRequest {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
@@ -653,7 +552,7 @@ async fn frecency_should_resume_cursor() {
Box::pin(async move { Ok(vec) })
});
- let res = SoupImpl::new(soup, frecency, NoopEmailService, NoopCommsService)
+ let res = SoupImpl::new(soup, frecency, NoopEmailPreviewService, NoopCommsService)
.get_user_soup(SoupRequest {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
@@ -742,7 +641,7 @@ async fn frecency_fallback_cursor_should_resume() {
Box::pin(async move { res })
});
- let res = SoupImpl::new(soup, frecency, NoopEmailService, NoopCommsService)
+ let res = SoupImpl::new(soup, frecency, NoopEmailPreviewService, NoopCommsService)
.get_user_soup(SoupRequest {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
@@ -810,7 +709,7 @@ async fn cursor_should_return_simple_sort() {
let res = SoupImpl::new(
soup_mock,
FrecencyQueryServiceImpl::new(MockFrecencyStorage::new()),
- NoopEmailService,
+ NoopEmailPreviewService,
NoopCommsService,
)
.get_user_soup(SoupRequest {
@@ -873,7 +772,7 @@ async fn cursor_should_return_frecency() {
Box::pin(async move { Ok(vec) })
});
- let res = SoupImpl::new(soup, frecency, NoopEmailService, NoopCommsService)
+ let res = SoupImpl::new(soup, frecency, NoopEmailPreviewService, NoopCommsService)
.get_user_soup(SoupRequest {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
@@ -927,7 +826,7 @@ async fn it_should_return_is_completed_true_for_completed_tasks() {
let res = SoupImpl::new(
soup_mock,
FrecencyQueryServiceImpl::new(MockFrecencyStorage::new()),
- NoopEmailService,
+ NoopEmailPreviewService,
NoopCommsService,
)
.get_user_soup(SoupRequest {
@@ -973,7 +872,7 @@ async fn it_should_return_is_completed_false_for_incomplete_tasks() {
let res = SoupImpl::new(
soup_mock,
FrecencyQueryServiceImpl::new(MockFrecencyStorage::new()),
- NoopEmailService,
+ NoopEmailPreviewService,
NoopCommsService,
)
.get_user_soup(SoupRequest {
@@ -1019,7 +918,7 @@ async fn it_should_return_is_completed_none_for_non_tasks() {
let res = SoupImpl::new(
soup_mock,
FrecencyQueryServiceImpl::new(MockFrecencyStorage::new()),
- NoopEmailService,
+ NoopEmailPreviewService,
NoopCommsService,
)
.get_user_soup(SoupRequest {
@@ -1077,7 +976,7 @@ async fn it_should_preserve_is_completed_for_mixed_items() {
let res = SoupImpl::new(
soup_mock,
FrecencyQueryServiceImpl::new(MockFrecencyStorage::new()),
- NoopEmailService,
+ NoopEmailPreviewService,
NoopCommsService,
)
.get_user_soup(SoupRequest {
@@ -1151,20 +1050,25 @@ async fn it_should_preserve_is_completed_in_by_ids_queries() {
Box::pin(async move { res })
});
- let res = SoupImpl::new(soup_mock, frecency, NoopEmailService, NoopCommsService)
- .get_user_soup(SoupRequest {
- email_preview_view: PreviewView::StandardLabel(
- email::domain::models::PreviewViewStandardLabel::Inbox,
- ),
- link_id: Some(Uuid::new_v4()),
- soup_type: SoupType::UnExpanded,
- limit: 3,
- cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),
- user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- })
- .await
- .unwrap()
- .unwrap_right();
+ let res = SoupImpl::new(
+ soup_mock,
+ frecency,
+ NoopEmailPreviewService,
+ NoopCommsService,
+ )
+ .get_user_soup(SoupRequest {
+ email_preview_view: PreviewView::StandardLabel(
+ email::domain::models::PreviewViewStandardLabel::Inbox,
+ ),
+ link_id: Some(Uuid::new_v4()),
+ soup_type: SoupType::UnExpanded,
+ limit: 3,
+ cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),
+ user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
+ })
+ .await
+ .unwrap()
+ .unwrap_right();
// Should have 20 items, verify is_completed values are preserved
assert_eq!(res.items.len(), 20);
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo.rs
index c9f7b08d5b..c24b22d92e 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo.rs
@@ -7,19 +7,19 @@ use crate::{
};
use either::Either;
use models_soup::{SoupProperty, item::SoupItem};
-use sqlx::PgPool;
+use readonly_pool::ReadOnlyPool;
use system_properties::SystemPropertyKey;
mod expanded;
mod unexpanded;
pub struct PgSoupRepo {
- inner: PgPool,
+ pool: ReadOnlyPool,
}
impl PgSoupRepo {
- pub fn new(inner: PgPool) -> Self {
- PgSoupRepo { inner }
+ pub fn new(pool: ReadOnlyPool) -> Self {
+ PgSoupRepo { pool }
}
}
@@ -35,7 +35,7 @@ impl SoupRepo for PgSoupRepo {
// Extract the EntityFilterAst from the tuple (Frecency, EntityFilterAst)
Either::Left(Either::Left(
expanded::dynamic::expanded_dynamic_cursor_soup(
- &self.inner,
+ &self.pool.0,
ExpandedDynamicCursorArgs {
user_id: req.user_id,
limit: req.limit,
@@ -47,7 +47,7 @@ impl SoupRepo for PgSoupRepo {
}
SimpleSortQuery::ItemsFilter(ast) => Either::Left(Either::Right(
expanded::dynamic::expanded_dynamic_cursor_soup(
- &self.inner,
+ &self.pool.0,
ExpandedDynamicCursorArgs {
user_id: req.user_id,
limit: req.limit,
@@ -58,7 +58,7 @@ impl SoupRepo for PgSoupRepo {
)),
SimpleSortQuery::FilterFrecency(f) => Either::Right(Either::Left(
expanded::by_cursor::no_frecency_expanded_generic_soup(
- &self.inner,
+ &self.pool.0,
req.user_id,
req.limit,
f,
@@ -66,7 +66,7 @@ impl SoupRepo for PgSoupRepo {
)),
SimpleSortQuery::NoFilter(f) => Either::Right(Either::Right(
expanded::by_cursor::expanded_generic_cursor_soup(
- &self.inner,
+ &self.pool.0,
req.user_id,
req.limit,
f,
@@ -86,7 +86,7 @@ impl SoupRepo for PgSoupRepo {
}
SimpleSortQuery::FilterFrecency(f) => Either::Right(Either::Left(
expanded::by_cursor::no_frecency_expanded_generic_soup(
- &self.inner,
+ &self.pool.0,
req.user_id,
req.limit,
f,
@@ -94,7 +94,7 @@ impl SoupRepo for PgSoupRepo {
)),
SimpleSortQuery::NoFilter(f) => Either::Right(Either::Right(
unexpanded::by_cursor::unexpanded_generic_cursor_soup(
- &self.inner,
+ &self.pool.0,
req.user_id,
req.limit,
f,
@@ -107,21 +107,21 @@ impl SoupRepo for PgSoupRepo {
&self,
req: AdvancedSortParams<'a>,
) -> impl Future<Output = Result<Vec<SoupItem>, Self::Err>> + Send {
- expanded::by_ids::expanded_soup_by_ids(&self.inner, req.user_id, req.entities)
+ expanded::by_ids::expanded_soup_by_ids(&self.pool.0, req.user_id, req.entities)
}
fn unexpanded_soup_by_ids<'a>(
&self,
req: AdvancedSortParams<'a>,
) -> impl Future<Output = Result<Vec<SoupItem>, Self::Err>> + Send {
- unexpanded::by_ids::unexpanded_soup_by_ids(&self.inner, req.user_id, req.entities)
+ unexpanded::by_ids::unexpanded_soup_by_ids(&self.pool.0, req.user_id, req.entities)
}
fn populate_properties(
&self,
items: &mut [SoupItem],
) -> impl Future<Output = Result<(), Self::Err>> + Send {
- populate_properties(&self.inner, items)
+ populate_properties(&self.pool.0, items)
}
}
@@ -146,7 +146,7 @@ fn type_err<E: std::fmt::Display>(e: E) -> sqlx::Error {
/// Tasks use `EntityType::Task` while regular documents use `EntityType::Document`.
#[tracing::instrument(err, skip(db, items))]
pub(crate) async fn populate_properties(
- db: &PgPool,
+ db: &sqlx::PgPool,
items: &mut [SoupItem],
) -> Result<(), sqlx::Error> {
let entity_refs = items