From 3ccadcd11e8effb2bf3b6cfd62beb687b43b9278 Mon Sep 17 00:00:00 2001 From: Evan Hutnik Date: Fri, 5 Dec 2025 16:00:19 -0500 Subject: [PATCH 1/2] Fixes --- ...0e64bad441f07222bfe922c9da81c7d2c3a47.json | 23 +++++++++++++++++++ ...6286344bdef6e504225847b094c87d7cdaa95.json | 23 ------------------- .../src/attachments/provider/mod.rs | 3 ++- .../api/email/attachments/get_document_id.rs | 1 + .../pubsub/backfill/backfill_attachment.rs | 1 + .../webhook/operations/upsert_message.rs | 1 + .../src/util/upload_attachment.rs | 12 +++++++--- 7 files changed, 37 insertions(+), 27 deletions(-) create mode 100644 rust/cloud-storage/email_db_client/.sqlx/query-e46bb839438b0dc805a6336d9ab0e64bad441f07222bfe922c9da81c7d2c3a47.json delete mode 100644 rust/cloud-storage/email_db_client/.sqlx/query-f253c2b856a3a264b27a08d68b36286344bdef6e504225847b094c87d7cdaa95.json diff --git a/rust/cloud-storage/email_db_client/.sqlx/query-e46bb839438b0dc805a6336d9ab0e64bad441f07222bfe922c9da81c7d2c3a47.json b/rust/cloud-storage/email_db_client/.sqlx/query-e46bb839438b0dc805a6336d9ab0e64bad441f07222bfe922c9da81c7d2c3a47.json new file mode 100644 index 00000000000..edb26597767 --- /dev/null +++ b/rust/cloud-storage/email_db_client/.sqlx/query-e46bb839438b0dc805a6336d9ab0e64bad441f07222bfe922c9da81c7d2c3a47.json @@ -0,0 +1,23 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT document_id\n FROM document_email de\n INNER JOIN \"Document\" d on de.document_id = d.id\n INNER JOIN email_attachments ea on de.email_attachment_id = ea.id\n INNER JOIN email_messages em on ea.message_id = em.id\n WHERE em.link_id = $1 AND email_attachment_id = $2 AND d.\"deletedAt\" IS NULL\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "document_id", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Uuid", + "Uuid" + ] + }, + "nullable": [ + false + ] + }, + "hash": "e46bb839438b0dc805a6336d9ab0e64bad441f07222bfe922c9da81c7d2c3a47" +} diff --git a/rust/cloud-storage/email_db_client/.sqlx/query-f253c2b856a3a264b27a08d68b36286344bdef6e504225847b094c87d7cdaa95.json b/rust/cloud-storage/email_db_client/.sqlx/query-f253c2b856a3a264b27a08d68b36286344bdef6e504225847b094c87d7cdaa95.json deleted file mode 100644 index 643f654141e..00000000000 --- a/rust/cloud-storage/email_db_client/.sqlx/query-f253c2b856a3a264b27a08d68b36286344bdef6e504225847b094c87d7cdaa95.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT document_id\n FROM document_email de\n INNER JOIN email_attachments ea on de.email_attachment_id = ea.id\n INNER JOIN email_messages em on ea.message_id = em.id\n WHERE em.link_id = $1 AND email_attachment_id = $2\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "document_id", - "type_info": "Text" - } - ], - "parameters": { - "Left": [ - "Uuid", - "Uuid" - ] - }, - "nullable": [ - false - ] - }, - "hash": "f253c2b856a3a264b27a08d68b36286344bdef6e504225847b094c87d7cdaa95" -} diff --git a/rust/cloud-storage/email_db_client/src/attachments/provider/mod.rs b/rust/cloud-storage/email_db_client/src/attachments/provider/mod.rs index 1cf24b58900..505f53299ec 100644 --- a/rust/cloud-storage/email_db_client/src/attachments/provider/mod.rs +++ b/rust/cloud-storage/email_db_client/src/attachments/provider/mod.rs @@ -320,9 +320,10 @@ pub async fn get_document_id_by_attachment_id( r#" SELECT document_id FROM document_email de + INNER JOIN "Document" d on de.document_id = d.id INNER JOIN email_attachments ea on de.email_attachment_id = ea.id INNER JOIN email_messages em on ea.message_id = em.id - WHERE em.link_id = $1 AND email_attachment_id = $2 + WHERE em.link_id = $1 AND email_attachment_id = $2 AND d."deletedAt" IS NULL "#, link_id, email_attachment_id, diff --git a/rust/cloud-storage/email_service/src/api/email/attachments/get_document_id.rs b/rust/cloud-storage/email_service/src/api/email/attachments/get_document_id.rs index f0ebd63dc31..2e27ce75640 100644 --- a/rust/cloud-storage/email_service/src/api/email/attachments/get_document_id.rs +++ b/rust/cloud-storage/email_service/src/api/email/attachments/get_document_id.rs @@ -101,6 +101,7 @@ pub async fn handler( &gmail_token, &link, &attachment_metadata, + false, ) .await .map_err(GetAttachmentDocumentIdError::UploadError)?; diff --git a/rust/cloud-storage/email_service/src/pubsub/backfill/backfill_attachment.rs b/rust/cloud-storage/email_service/src/pubsub/backfill/backfill_attachment.rs index e22e3a89b59..479211b64a5 100644 --- a/rust/cloud-storage/email_service/src/pubsub/backfill/backfill_attachment.rs +++ b/rust/cloud-storage/email_service/src/pubsub/backfill/backfill_attachment.rs @@ -27,6 +27,7 @@ pub async fn backfill_attachment( access_token, link, &p.metadata, + true, ) .await .map_err(|e| { diff --git a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs index 887877e56dd..ebb8a2fd0a7 100644 --- a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs +++ b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs @@ -228,6 +228,7 @@ async fn handle_attachment_upload( gmail_access_token, link, &attachment, + false, ) .await { diff --git a/rust/cloud-storage/email_service/src/util/upload_attachment.rs b/rust/cloud-storage/email_service/src/util/upload_attachment.rs index 9a4f49cbe7e..0bce22c2205 100644 --- a/rust/cloud-storage/email_service/src/util/upload_attachment.rs +++ b/rust/cloud-storage/email_service/src/util/upload_attachment.rs @@ -20,6 +20,7 @@ pub async fn upload_attachment( access_token: &str, link: &link::Link, p: &AttachmentUploadMetadata, + backfill: bool, ) -> anyhow::Result { // 1. Check rate limits before making a Gmail API call. check_gmail_rate_limit( @@ -41,8 +42,10 @@ pub async fn upload_attachment( let (file_name, file_type) = determine_file_metadata(p)?; // 5. Create the document record in DSS and get a presigned URL for the upload. - let dss_response = - create_dss_document_record(dss_client, link, p, &hex_hash, &file_name, &file_type).await?; + let dss_response = create_dss_document_record( + dss_client, link, p, &hex_hash, &file_name, &file_type, backfill, + ) + .await?; // 6. Upload the attachment data to the presigned URL. upload_data_to_presigned_url(&dss_response, attachment_data, &base64_hash).await?; @@ -115,7 +118,10 @@ async fn create_dss_document_record( hex_hash: &str, file_name: &str, file_type: &str, + backfill: bool, ) -> anyhow::Result { + let created_at = backfill.then_some(p.internal_date_ts); + let request = CreateDocumentRequest { id: None, sha: hex_hash.to_string(), @@ -127,7 +133,7 @@ async fn create_dss_document_record( branched_from_version_id: None, job_id: None, project_id: None, - created_at: Some(p.internal_date_ts), + created_at, email_attachment_id: Some(p.attachment_db_id), is_task: false, }; From feff80148725320f8df0be10301a8b3b5f3ff694 Mon Sep 17 00:00:00 2001 From: Evan Hutnik Date: Mon, 8 Dec 2025 10:08:28 -0500 Subject: [PATCH 2/2] Comment --- rust/cloud-storage/email_service/src/util/upload_attachment.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rust/cloud-storage/email_service/src/util/upload_attachment.rs b/rust/cloud-storage/email_service/src/util/upload_attachment.rs index 5fc1e3b4faf..f1b88d54b44 100644 --- a/rust/cloud-storage/email_service/src/util/upload_attachment.rs +++ b/rust/cloud-storage/email_service/src/util/upload_attachment.rs @@ -120,6 +120,8 @@ async fn create_dss_document_record( file_type: &str, backfill: bool, ) -> anyhow::Result { + // if we are backfilling, use the email timestamp. if it's an on-demand upload, use the current + // time so the document shows up at the top of soup views. let created_at = backfill.then_some(p.internal_date_ts); let request = CreateDocumentRequest {