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(email-service): Delete expired links (#955)

Evan Hutnik8b990f27f286
diff --git a/infra/stacks/email-service/Pulumi.dev.yaml b/infra/stacks/email-service/Pulumi.dev.yaml
index 216802c812..c3a0205b71 100644
--- a/infra/stacks/email-service/Pulumi.dev.yaml
+++ b/infra/stacks/email-service/Pulumi.dev.yaml
@@ -22,3 +22,5 @@ config:
email-service:presigned_url_ttl_secs: 3600
email-service:gmail_gcp_queue: gmail-gcp-queue-dev
email-service:macro_db_secret_key: macro-db-dev
+ email-service:delete_unused_after_days: 5000
+ email-service:delete_inactive_after_days: 5000
diff --git a/infra/stacks/email-service/Pulumi.prod.yaml b/infra/stacks/email-service/Pulumi.prod.yaml
index 43c90a1035..53bce2e16a 100644
--- a/infra/stacks/email-service/Pulumi.prod.yaml
+++ b/infra/stacks/email-service/Pulumi.prod.yaml
@@ -22,3 +22,5 @@ config:
email-service:presigned_url_ttl_secs: 3600
email-service:gmail_gcp_queue: gmail-gcp-queue-prod
email-service:macro_db_secret_key: macro-db-prod
+ email-service:delete_unused_after_days: 14
+ email-service:delete_inactive_after_days: 60
diff --git a/infra/stacks/email-service/index.ts b/infra/stacks/email-service/index.ts
index 7495db8a13..e4d6015363 100644
--- a/infra/stacks/email-service/index.ts
+++ b/infra/stacks/email-service/index.ts
@@ -515,6 +515,9 @@ new EmailPubSubWorkers('email-pubsub-workers', {
containerEnvVars,
});
+const DELETE_UNUSED_AFTER_DAYS = config.require(`delete_unused_after_days`);
+const DELETE_INACTIVE_AFTER_DAYS = config.require(`delete_inactive_after_days`);
+
const emailRefreshHandler = new EmailRefreshHandler('email-refresh-handler', {
queueArns: [linkManagerQueueArn],
vpc: coparse_api_vpc,
@@ -523,6 +526,8 @@ const emailRefreshHandler = new EmailRefreshHandler('email-refresh-handler', {
LINK_MANAGER_QUEUE: pulumi.interpolate`${linkManagerQueueName}`,
ENVIRONMENT: stack,
RUST_LOG: 'email_refresh_handler=info',
+ DELETE_UNUSED_AFTER_DAYS: pulumi.interpolate`${DELETE_UNUSED_AFTER_DAYS}`,
+ DELETE_INACTIVE_AFTER_DAYS: pulumi.interpolate`${DELETE_INACTIVE_AFTER_DAYS}`,
},
tags,
});
diff --git a/infra/stacks/email-service/refresh_lambda.ts b/infra/stacks/email-service/refresh_lambda.ts
index 528409f819..25245e1382 100644
--- a/infra/stacks/email-service/refresh_lambda.ts
+++ b/infra/stacks/email-service/refresh_lambda.ts
@@ -12,6 +12,8 @@ export type EnvVars = {
LINK_MANAGER_QUEUE: pulumi.Output<string> | string;
ENVIRONMENT: pulumi.Output<string> | string;
RUST_LOG: pulumi.Output<string> | string;
+ DELETE_UNUSED_AFTER_DAYS: pulumi.Output<string> | string;
+ DELETE_INACTIVE_AFTER_DAYS: pulumi.Output<string> | string;
};
type Args = {
diff --git a/rust/cloud-storage/CLAUDE.md b/rust/cloud-storage/CLAUDE.md
index 84571ea613..ac0453e36a 100644
--- a/rust/cloud-storage/CLAUDE.md
+++ b/rust/cloud-storage/CLAUDE.md
@@ -289,6 +289,12 @@ async fn test_something() {
This keeps implementation files focused and makes tests easier to locate and maintain.
+### Tracing
+
+- Include `err` when adding the `tracing::instrument` attribute to functions. Never include `level = "info"`.
+- When including an error with a log, include it like so: `tracing::error!(error=?e, "error msg");`
+don't inject it directly into the error message.
+
## Development Memories
### DB Crate Changes
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index e8d89fb21d..3cf51a2691 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -3110,6 +3110,7 @@ dependencies = [
"aws_lambda_events",
"chrono",
"lambda_runtime",
+ "macro_db_migrator",
"macro_entrypoint",
"macro_env",
"model",
@@ -3118,6 +3119,7 @@ dependencies = [
"sqs_client",
"tokio",
"tracing",
+ "uuid",
]
[[package]]
diff --git a/rust/cloud-storage/email_refresh_handler/.sqlx/query-c4f9c493fa0e3816a20a0494d5513617cdb7a83c37ecdb2df1faae1a83e14e37.json b/rust/cloud-storage/email_refresh_handler/.sqlx/query-c4f9c493fa0e3816a20a0494d5513617cdb7a83c37ecdb2df1faae1a83e14e37.json
new file mode 100644
index 0000000000..787cf562dc
--- /dev/null
+++ b/rust/cloud-storage/email_refresh_handler/.sqlx/query-c4f9c493fa0e3816a20a0494d5513617cdb7a83c37ecdb2df1faae1a83e14e37.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n -- Condition A: Created > X days ago and has NO history - hasn't viewed a thread\n SELECT\n l.id AS \"link_id!\"\n FROM\n public.email_links l\n LEFT JOIN\n public.email_user_history h ON l.id = h.link_id\n WHERE\n l.macro_id NOT LIKE '%@macro.com'\n AND l.created_at < NOW() - (make_interval(days => $1))\n GROUP BY\n l.id\n HAVING\n COUNT(h.link_id) = 0\n\n UNION\n\n -- Condition B: Has history rows, but latest thread viewed was > Y days ago\n SELECT\n l.id AS \"link_id!\"\n FROM\n public.email_links l\n JOIN\n public.email_user_history h ON l.id = h.link_id\n WHERE\n l.macro_id NOT LIKE '%@macro.com'\n GROUP BY\n l.id\n HAVING\n MAX(h.updated_at) < NOW() - (make_interval(days => $2))\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "link_id!",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int4",
+ "Int4"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "c4f9c493fa0e3816a20a0494d5513617cdb7a83c37ecdb2df1faae1a83e14e37"
+}
diff --git a/rust/cloud-storage/email_refresh_handler/Cargo.toml b/rust/cloud-storage/email_refresh_handler/Cargo.toml
index b61ab57534..b557061f6e 100644
--- a/rust/cloud-storage/email_refresh_handler/Cargo.toml
+++ b/rust/cloud-storage/email_refresh_handler/Cargo.toml
@@ -19,6 +19,10 @@ sqlx = { workspace = true }
sqs_client = { path = "../sqs_client" }
tokio = { workspace = true }
tracing = { workspace = true }
+uuid = { workspace = true }
[package.metadata.cargo-machete]
ignored = ["openssl"]
+
+[dev-dependencies]
+macro_db_migrator = { path = "../macro_db_migrator" }
\ No newline at end of file
diff --git a/rust/cloud-storage/email_refresh_handler/fixtures/fetch_inactive_links.sql b/rust/cloud-storage/email_refresh_handler/fixtures/fetch_inactive_links.sql
new file mode 100644
index 0000000000..281e98dd06
--- /dev/null
+++ b/rust/cloud-storage/email_refresh_handler/fixtures/fetch_inactive_links.sql
@@ -0,0 +1,82 @@
+-- SQL fixture for fetch_inactive_link_ids tests
+-- Tests the query that identifies links eligible for deletion
+
+------------------------------------------------------------
+-- Link 1: Old link with NO history (should be deleted - Condition A)
+-- Created 40 days ago, no user_history entries
+------------------------------------------------------------
+
+INSERT INTO email_links (id, macro_id, fusionauth_user_id, email_address, provider, is_sync_active, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-000000000001', 'macro|[email protected]', '00000000-0000-0000-0000-0000000a0001',
+ '[email protected]', 'GMAIL', true, NOW() - INTERVAL '40 days', NOW() - INTERVAL '40 days');
+
+-- Thread for link 1 (needed for FK but no history will reference it)
+INSERT INTO email_threads (id, link_id, inbox_visible, is_read, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-0000000b0001', '00000000-0000-0000-0000-000000000001',
+ true, false, NOW() - INTERVAL '40 days', NOW() - INTERVAL '40 days');
+
+------------------------------------------------------------
+-- Link 2: Link with STALE history (should be deleted - Condition B)
+-- Has history, but last activity was 90 days ago
+------------------------------------------------------------
+
+INSERT INTO email_links (id, macro_id, fusionauth_user_id, email_address, provider, is_sync_active, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-000000000002', 'macro|[email protected]', '00000000-0000-0000-0000-0000000a0002',
+ '[email protected]', 'GMAIL', true, NOW() - INTERVAL '100 days', NOW() - INTERVAL '90 days');
+
+-- Thread for link 2
+INSERT INTO email_threads (id, link_id, inbox_visible, is_read, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-0000000b0002', '00000000-0000-0000-0000-000000000002',
+ true, false, NOW() - INTERVAL '100 days', NOW() - INTERVAL '90 days');
+
+-- User history for link 2 (stale - 90 days old)
+INSERT INTO email_user_history (link_id, thread_id, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-000000000002', '00000000-0000-0000-0000-0000000b0002',
+ NOW() - INTERVAL '90 days', NOW() - INTERVAL '90 days');
+
+------------------------------------------------------------
+-- Link 3: ACTIVE link with recent history (should NOT be deleted)
+-- Has history updated recently (5 days ago)
+------------------------------------------------------------
+
+INSERT INTO email_links (id, macro_id, fusionauth_user_id, email_address, provider, is_sync_active, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-000000000003', 'macro|[email protected]', '00000000-0000-0000-0000-0000000a0003',
+ '[email protected]', 'GMAIL', true, NOW() - INTERVAL '60 days', NOW() - INTERVAL '5 days');
+
+-- Thread for link 3
+INSERT INTO email_threads (id, link_id, inbox_visible, is_read, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-0000000b0003', '00000000-0000-0000-0000-000000000003',
+ true, false, NOW() - INTERVAL '60 days', NOW() - INTERVAL '5 days');
+
+-- User history for link 3 (recent - 5 days old)
+INSERT INTO email_user_history (link_id, thread_id, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-000000000003', '00000000-0000-0000-0000-0000000b0003',
+ NOW() - INTERVAL '60 days', NOW() - INTERVAL '5 days');
+
+------------------------------------------------------------
+-- Link 4: NEW link with no history (should NOT be deleted)
+-- Created recently (10 days ago), no history yet
+------------------------------------------------------------
+
+INSERT INTO email_links (id, macro_id, fusionauth_user_id, email_address, provider, is_sync_active, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-000000000004', 'macro|[email protected]', '00000000-0000-0000-0000-0000000a0004',
+ '[email protected]', 'GMAIL', true, NOW() - INTERVAL '10 days', NOW() - INTERVAL '10 days');
+
+-- Thread for link 4
+INSERT INTO email_threads (id, link_id, inbox_visible, is_read, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-0000000b0004', '00000000-0000-0000-0000-000000000004',
+ true, false, NOW() - INTERVAL '10 days', NOW() - INTERVAL '10 days');
+
+------------------------------------------------------------
+-- Link 5: INTERNAL @macro.com link (should NEVER be deleted)
+-- Old link with no history, but has @macro.com in macro_id
+------------------------------------------------------------
+
+INSERT INTO email_links (id, macro_id, fusionauth_user_id, email_address, provider, is_sync_active, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-000000000005', '[email protected]', '00000000-0000-0000-0000-0000000a0005',
+ '[email protected]', 'GMAIL', true, NOW() - INTERVAL '200 days', NOW() - INTERVAL '200 days');
+
+-- Thread for link 5
+INSERT INTO email_threads (id, link_id, inbox_visible, is_read, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-0000000b0005', '00000000-0000-0000-0000-000000000005',
+ true, false, NOW() - INTERVAL '200 days', NOW() - INTERVAL '200 days');
\ No newline at end of file
diff --git a/rust/cloud-storage/email_refresh_handler/src/config.rs b/rust/cloud-storage/email_refresh_handler/src/config.rs
index d3ededa3f7..7da5a96c8f 100644
--- a/rust/cloud-storage/email_refresh_handler/src/config.rs
+++ b/rust/cloud-storage/email_refresh_handler/src/config.rs
@@ -12,6 +12,12 @@ pub struct Config {
/// The environment we are in
#[allow(dead_code)]
pub environment: Environment,
+
+ /// How many days to keep never-used links around
+ pub delete_unused_after_days: u32,
+
+ /// How many days to keep inactive links around
+ pub delete_inactive_after_days: u32,
}
impl Config {
@@ -24,10 +30,22 @@ impl Config {
let environment = Environment::new_or_prod();
+ let delete_unused_after_days = std::env::var("DELETE_UNUSED_AFTER_DAYS")
+ .context("DELETE_UNUSED_AFTER_DAYS must be provided")?
+ .parse()
+ .context("DELETE_UNUSED_AFTER_DAYS must be a valid u32")?;
+
+ let delete_inactive_after_days = std::env::var("DELETE_INACTIVE_AFTER_DAYS")
+ .context("DELETE_INACTIVE_AFTER_DAYS must be provided")?
+ .parse()
+ .context("DELETE_INACTIVE_AFTER_DAYS must be a valid u32")?;
+
Ok(Config {
database_url,
link_manager_queue,
environment,
+ delete_unused_after_days,
+ delete_inactive_after_days,
})
}
}
diff --git a/rust/cloud-storage/email_refresh_handler/src/context.rs b/rust/cloud-storage/email_refresh_handler/src/context.rs
index 7b9c0db64e..6d818ba0a0 100644
--- a/rust/cloud-storage/email_refresh_handler/src/context.rs
+++ b/rust/cloud-storage/email_refresh_handler/src/context.rs
@@ -1,7 +1,10 @@
+use crate::config;
use std::sync::Arc;
+/// Context for refresh handler
#[derive(Clone)]
pub struct Context {
pub db: sqlx::Pool<sqlx::Postgres>,
pub sqs_client: Arc<sqs_client::SQS>,
+ pub config: config::Config,
}
diff --git a/rust/cloud-storage/email_refresh_handler/src/handler.rs b/rust/cloud-storage/email_refresh_handler/src/handler.rs
index 73119f2038..0adaf0559c 100644
--- a/rust/cloud-storage/email_refresh_handler/src/handler.rs
+++ b/rust/cloud-storage/email_refresh_handler/src/handler.rs
@@ -5,9 +5,11 @@ use lambda_runtime::{
Error, LambdaEvent,
tracing::{self},
};
+use macro_env::Environment;
use models_email::email::service::pubsub::LinkManagerMessage;
use models_email::service::pubsub::LinkManagerOperation;
-use sqlx::Type;
+use sqlx::types::uuid;
+use sqlx::{Pool, Postgres, Type};
#[derive(Type, Debug, Clone, Copy)]
#[sqlx(type_name = "email_user_provider_enum", rename_all = "UPPERCASE")]
@@ -20,6 +22,16 @@ pub async fn handler(
ctx: context::Context,
_event: LambdaEvent<EventBridgeEvent>,
) -> Result<(), Error> {
+ if matches!(ctx.config.environment, Environment::Production) {
+ tokio::try_join!(send_refresh_messages(&ctx), send_delete_messages(&ctx))?;
+ } else {
+ send_refresh_messages(&ctx).await?;
+ }
+ Ok(())
+}
+
+/// send refresh notifications for active links
+async fn send_refresh_messages(ctx: &context::Context) -> Result<(), Error> {
let current_hour = chrono::Utc::now().hour() as i32;
let provider_filter = DbUserProvider::Gmail;
@@ -40,19 +52,15 @@ pub async fn handler(
.fetch_all(&ctx.db)
.await
.unwrap_or_else(|e| {
- tracing::error!("Error fetching notifications: {}", e);
+ tracing::error!(error = ?e, "Error fetching links for refresh");
Vec::new()
});
if !link_ids.is_empty() {
tracing::info!(
- "Hour {}. Sending refresh notifications for users with link_ids: {}",
+ "Hour {}. Sending refresh notifications for {} links",
current_hour,
- link_ids
- .iter()
- .map(|id| id.to_string())
- .collect::<Vec<String>>()
- .join(", ")
+ link_ids.len()
);
for link_id in link_ids {
@@ -69,6 +77,88 @@ pub async fn handler(
.ok();
}
}
+ Ok(())
+}
+
+/// delete inactive links from our database
+async fn send_delete_messages(ctx: &context::Context) -> Result<(), Error> {
+ let inactive_links = fetch_inactive_link_ids(
+ &ctx.db,
+ ctx.config.delete_unused_after_days as i32,
+ ctx.config.delete_inactive_after_days as i32,
+ )
+ .await
+ .unwrap_or_else(|e| {
+ tracing::error!(error=?e, "Error fetching inactive links for deletion");
+ Vec::new()
+ });
+
+ if !inactive_links.is_empty() {
+ tracing::info!(
+ "Sending delete notifications for {} inactive links",
+ inactive_links.len()
+ );
+
+ for link_id in inactive_links {
+ let notif = LinkManagerMessage {
+ link_id,
+ operation: LinkManagerOperation::Delete,
+ };
+ ctx.sqs_client
+ .enqueue_link_manager_notification(notif)
+ .await
+ .inspect_err(|e| {
+ tracing::error!(error=?e, link_id=%link_id, "Error enqueueing delete notification for inactive link");
+ })
+ .ok();
+ }
+ }
Ok(())
}
+
+/// Fetch link IDs that should be deleted due to inactivity
+pub async fn fetch_inactive_link_ids(
+ pool: &Pool<Postgres>,
+ delete_unused_after_days: i32,
+ delete_inactive_after_days: i32,
+) -> Result<Vec<uuid::Uuid>, sqlx::Error> {
+ sqlx::query_scalar!(
+ r#"
+ -- Condition A: Created > X days ago and has NO history - hasn't viewed a thread
+ SELECT
+ l.id AS "link_id!"
+ FROM
+ public.email_links l
+ LEFT JOIN
+ public.email_user_history h ON l.id = h.link_id
+ WHERE
+ l.macro_id NOT LIKE '%@macro.com'
+ AND l.created_at < NOW() - (make_interval(days => $1))
+ GROUP BY
+ l.id
+ HAVING
+ COUNT(h.link_id) = 0
+
+ UNION
+
+ -- Condition B: Has history rows, but latest thread viewed was > Y days ago
+ SELECT
+ l.id AS "link_id!"
+ FROM
+ public.email_links l
+ JOIN
+ public.email_user_history h ON l.id = h.link_id
+ WHERE
+ l.macro_id NOT LIKE '%@macro.com'
+ GROUP BY
+ l.id
+ HAVING
+ MAX(h.updated_at) < NOW() - (make_interval(days => $2))
+ "#,
+ delete_unused_after_days,
+ delete_inactive_after_days
+ )
+ .fetch_all(pool)
+ .await
+}
diff --git a/rust/cloud-storage/email_refresh_handler/src/main.rs b/rust/cloud-storage/email_refresh_handler/src/main.rs
index 2f62e3f67c..385c6e526d 100644
--- a/rust/cloud-storage/email_refresh_handler/src/main.rs
+++ b/rust/cloud-storage/email_refresh_handler/src/main.rs
@@ -1,6 +1,8 @@
mod config;
mod context;
mod handler;
+#[cfg(test)]
+mod test;
use anyhow::Context;
use aws_lambda_events::event::eventbridge::EventBridgeEvent;
@@ -36,6 +38,7 @@ async fn main() -> Result<(), Error> {
let ctx = context::Context {
db,
sqs_client: Arc::new(sqs_client),
+ config,
};
let func = service_fn(move |event: LambdaEvent<EventBridgeEvent>| {
diff --git a/rust/cloud-storage/email_refresh_handler/src/test.rs b/rust/cloud-storage/email_refresh_handler/src/test.rs
new file mode 100644
index 0000000000..1f43418300
--- /dev/null
+++ b/rust/cloud-storage/email_refresh_handler/src/test.rs
@@ -0,0 +1,101 @@
+use crate::handler::fetch_inactive_link_ids;
+use anyhow::Result;
+use macro_db_migrator::MACRO_DB_MIGRATIONS;
+use sqlx::{Pool, Postgres};
+use uuid::Uuid;
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../fixtures", scripts("fetch_inactive_links"))
+)]
+async fn fetch_inactive_link_ids_returns_unused_links(pool: Pool<Postgres>) -> Result<()> {
+ const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
+
+ // Link created 40 days ago with no history should be returned (threshold: 30 days)
+ let result = fetch_inactive_link_ids(&pool, 30, 60).await?;
+
+ let unused_link_id = Uuid::parse_str("00000000-0000-0000-0000-000000000001")?;
+ assert!(
+ result.contains(&unused_link_id),
+ "Should include link with no history older than threshold"
+ );
+
+ Ok(())
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../fixtures", scripts("fetch_inactive_links"))
+)]
+async fn fetch_inactive_link_ids_returns_stale_history_links(pool: Pool<Postgres>) -> Result<()> {
+ // Link with history last updated 90 days ago should be returned (threshold: 60 days)
+ let result = fetch_inactive_link_ids(&pool, 30, 60).await?;
+
+ let stale_link_id = Uuid::parse_str("00000000-0000-0000-0000-000000000002")?;
+ assert!(
+ result.contains(&stale_link_id),
+ "Should include link with stale history"
+ );
+
+ Ok(())
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../fixtures", scripts("fetch_inactive_links"))
+)]
+async fn fetch_inactive_link_ids_excludes_active_links(pool: Pool<Postgres>) -> Result<()> {
+ let result = fetch_inactive_link_ids(&pool, 30, 60).await?;
+
+ // Link with recent history should NOT be returned
+ let active_link_id = Uuid::parse_str("00000000-0000-0000-0000-000000000003")?;
+ assert!(
+ !result.contains(&active_link_id),
+ "Should not include link with recent history"
+ );
+
+ // Recently created link with no history should NOT be returned
+ let new_link_id = Uuid::parse_str("00000000-0000-0000-0000-000000000004")?;
+ assert!(
+ !result.contains(&new_link_id),
+ "Should not include recently created link"
+ );
+
+ Ok(())
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../fixtures", scripts("fetch_inactive_links"))
+)]
+async fn fetch_inactive_link_ids_excludes_macro_internal_links(pool: Pool<Postgres>) -> Result<()> {
+ let result = fetch_inactive_link_ids(&pool, 30, 60).await?;
+
+ // Links with @macro.com in macro_id should never be deleted
+ let internal_link_id = Uuid::parse_str("00000000-0000-0000-0000-000000000005")?;
+ assert!(
+ !result.contains(&internal_link_id),
+ "Should not include internal @macro.com links"
+ );
+
+ Ok(())
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../fixtures", scripts("fetch_inactive_links"))
+)]
+async fn fetch_inactive_link_ids_respects_threshold_parameters(pool: Pool<Postgres>) -> Result<()> {
+ // With very high thresholds, nothing should be returned
+ let result = fetch_inactive_link_ids(&pool, 365, 365).await?;
+ assert!(result.is_empty(), "High thresholds should return no links");
+
+ // With very low thresholds, more links should be returned
+ let result = fetch_inactive_link_ids(&pool, 1, 1).await?;
+ assert!(
+ !result.is_empty(),
+ "Low thresholds should return some links"
+ );
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/justfile b/rust/cloud-storage/justfile
index 0efea13767..b18532dd0b 100644
--- a/rust/cloud-storage/justfile
+++ b/rust/cloud-storage/justfile
@@ -49,6 +49,7 @@ setup_test_envs:
echo "DATABASE_URL={{ MACRODB }}" >> ./properties_db_client/.env
echo "DATABASE_URL={{ MACRODB }}" >> ./macro_db_client/.env
echo "DATABASE_URL={{ MACRODB }}" >> ./email_db_client/.env
+ echo "DATABASE_URL={{ MACRODB }}" >> ./email_refresh_handler/.env
echo "DATABASE_URL={{ MACRODB }}" >> ./comms_db_client/.env
echo "DATABASE_URL={{ MACRODB }}" >> ./comms/.env
echo "DATABASE_URL={{ MACRODB }}" >> ./document_cognition_service/.env
diff --git a/rust/cloud-storage/target/lambda/email_refresh_handler/bootstrap.zip b/rust/cloud-storage/target/lambda/email_refresh_handler/bootstrap.zip
index 2a00d3a291..a1b67fd7a9 100644
Binary files a/rust/cloud-storage/target/lambda/email_refresh_handler/bootstrap.zip and b/rust/cloud-storage/target/lambda/email_refresh_handler/bootstrap.zip differ