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
fix(email): skip no-op email_links sync-status updates (#5489)
Will Hutchinson3b7bffa92178
diff --git a/.sqlx/query-bc7ef8662eb6050c09246ebc169f91d523c596874f216a10180a377bbaf7a1eb.json b/.sqlx/query-9ffed25f4e006eb1bd06d834743632fc08829762b7105fdadd7268b32a11c19b.jsonsimilarity index 56%rename from .sqlx/query-bc7ef8662eb6050c09246ebc169f91d523c596874f216a10180a377bbaf7a1eb.jsonrename to .sqlx/query-9ffed25f4e006eb1bd06d834743632fc08829762b7105fdadd7268b32a11c19b.jsonindex 510e858534..1b1b610823 100644--- a/.sqlx/query-bc7ef8662eb6050c09246ebc169f91d523c596874f216a10180a377bbaf7a1eb.json+++ b/.sqlx/query-9ffed25f4e006eb1bd06d834743632fc08829762b7105fdadd7268b32a11c19b.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n UPDATE email_links\n SET is_sync_active = $2, updated_at = NOW()\n WHERE id = $1\n ",+ "query": "\n UPDATE email_links\n SET is_sync_active = $2, updated_at = NOW()\n WHERE id = $1 AND is_sync_active IS DISTINCT FROM $2\n ","describe": {"columns": [],"parameters": {@@ -11,5 +11,5 @@},"nullable": []},- "hash": "bc7ef8662eb6050c09246ebc169f91d523c596874f216a10180a377bbaf7a1eb"+ "hash": "9ffed25f4e006eb1bd06d834743632fc08829762b7105fdadd7268b32a11c19b"}diff --git a/crates/email_db_client/src/links/update.rs b/crates/email_db_client/src/links/update.rsindex 3b7b5b3dc2..1ac11ca3de 100644--- a/crates/email_db_client/src/links/update.rs+++ b/crates/email_db_client/src/links/update.rs@@ -80,6 +80,10 @@ pub async fn clear_link_needs_reauth(pool: &PgPool, link_id: Uuid) -> anyhow::Re/// Updates the sync active status for a link by its ID./// Also updates the updated_at timestamp to the current time.+///+/// A no-op when the status already matches, so a redelivered delete message+/// returns immediately instead of queueing behind the row lock held by the+/// first delivery's cascading `DELETE FROM email_links`.#[tracing::instrument(skip(pool), err)]pub async fn update_link_sync_status(pool: &PgPool,@@ -90,7 +94,7 @@ pub async fn update_link_sync_status(r#"UPDATE email_linksSET is_sync_active = $2, updated_at = NOW()- WHERE id = $1+ WHERE id = $1 AND is_sync_active IS DISTINCT FROM $2"#,link_id,is_sync_activediff --git a/crates/email_db_client/src/links/update/test.rs b/crates/email_db_client/src/links/update/test.rsindex 1e6db677d3..fba213437d 100644--- a/crates/email_db_client/src/links/update/test.rs+++ b/crates/email_db_client/src/links/update/test.rs@@ -57,6 +57,23 @@ async fn clear_needs_reauth_resets_health(pool: Pool<Postgres>) -> anyhow::ResulOk(())}+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn update_sync_status_skips_row_when_already_set(pool: Pool<Postgres>) -> anyhow::Result<()> {+ let id = insert_test_link(&pool, "[email protected]").await?;++ update_link_sync_status(&pool, id, false).await?;+ let link = fetch_link_by_id(&pool, id).await?.expect("link exists");+ assert!(!link.is_sync_active);++ // A repeat call must not touch the row (updated_at unchanged), so it never+ // waits on a row lock held by an in-flight link deletion.+ update_link_sync_status(&pool, id, false).await?;+ let after = fetch_link_by_id(&pool, id).await?.expect("link exists");+ assert_eq!(after.updated_at, link.updated_at);++ Ok(())+}+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]async fn set_needs_reauth_on_missing_link_is_not_a_transition(pool: Pool<Postgres>,