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) delete from names index when delete item events are sent (#320)
Will Hutchinsonb5e7edfd868a
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex fee279780c..246d733fc6 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -7352,6 +7352,7 @@ dependencies = ["macro_uuid","mention_utils","model",+ "models_opensearch","models_search","nom 8.0.0","opensearch_client",diff --git a/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs b/rust/cloud-storage/comms_service/src/api/channels/create_channel.rsindex 98fcf2887d..e923f65845 100644--- a/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs+++ b/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs@@ -10,7 +10,7 @@ use model::comms::ChannelType;use model::user::UserContext;use models_opensearch::SearchEntityType;use serde::{Deserialize, Serialize};-use sqs_client::search::{SearchQueueMessage, name::UpdateEntityName};+use sqs_client::search::{SearchQueueMessage, name::EntityName};use tracing::Instrument;use utoipa::ToSchema;@@ -123,7 +123,7 @@ pub async fn create_channel_handler(let _ = sqs_client.send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(- UpdateEntityName {+ EntityName {entity_id: channel_id,entity_type: SearchEntityType::Channels,},diff --git a/rust/cloud-storage/comms_service/src/api/channels/delete_channel.rs b/rust/cloud-storage/comms_service/src/api/channels/delete_channel.rsindex dbb5bc2127..a353ac7cc3 100644--- a/rust/cloud-storage/comms_service/src/api/channels/delete_channel.rs+++ b/rust/cloud-storage/comms_service/src/api/channels/delete_channel.rs@@ -45,6 +45,11 @@ pub async fn delete_channel_handler(None::<&str>,);+ service::search::send_remove_channel_name_to_search_extractor_queue(+ &ctx.sqs_client,+ &channel_id,+ );+Ok((StatusCode::NOT_FOUND,"channel successfully deleted".to_string(),diff --git a/rust/cloud-storage/comms_service/src/api/channels/patch_channel.rs b/rust/cloud-storage/comms_service/src/api/channels/patch_channel.rsindex a7f55de2f3..71169081b8 100644--- a/rust/cloud-storage/comms_service/src/api/channels/patch_channel.rs+++ b/rust/cloud-storage/comms_service/src/api/channels/patch_channel.rs@@ -61,7 +61,7 @@ pub async fn patch_channel_handler(let _ = sqs_client.send_message_to_search_event_queue(sqs_client::search::SearchQueueMessage::UpdateEntityName(- sqs_client::search::name::UpdateEntityName {+ sqs_client::search::name::EntityName {entity_id: channel_id,entity_type: SearchEntityType::Channels,},diff --git a/rust/cloud-storage/comms_service/src/service/search.rs b/rust/cloud-storage/comms_service/src/service/search.rsindex 0587314b73..e3838aabba 100644--- a/rust/cloud-storage/comms_service/src/service/search.rs+++ b/rust/cloud-storage/comms_service/src/service/search.rs@@ -73,3 +73,37 @@ pub fn send_remove_channel_message_to_search_extractor_queue(});}}++#[tracing::instrument(skip(sqs_client))]+pub fn send_remove_channel_name_to_search_extractor_queue(+ sqs_client: &sqs_client::SQS,+ channel_id: &uuid::Uuid,+) {+ #[cfg(feature = "channel_search")]+ {+ use tracing::Instrument;++ tracing::trace!("enqueueing message to search");++ tokio::spawn({+ let sqs_client = sqs_client.clone();+ let channel_id = *channel_id;+ async move {+ let _ = sqs_client+ .send_message_to_search_event_queue(+ sqs_client::search::SearchQueueMessage::RemoveEntityName(+ sqs_client::search::name::EntityName {+ entity_id: channel_id,+ entity_type: models_opensearch::SearchEntityType::Channels,+ },+ ),+ )+ .await+ .inspect_err(|e| {+ tracing::error!(error=?e, "SEARCH_QUEUE unable to enqueue message");+ });+ }+ .in_current_span()+ });+ }+}diff --git a/rust/cloud-storage/document_cognition_service/src/api/chats/create_user_chat.rs b/rust/cloud-storage/document_cognition_service/src/api/chats/create_user_chat.rsindex 60aae1cf31..744bd640e0 100644--- a/rust/cloud-storage/document_cognition_service/src/api/chats/create_user_chat.rs+++ b/rust/cloud-storage/document_cognition_service/src/api/chats/create_user_chat.rs@@ -190,7 +190,7 @@ pub async fn create_user_chat_v2(let _ = sqs_client.send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(- sqs_client::search::name::UpdateEntityName {+ sqs_client::search::name::EntityName {entity_id: chat_id,entity_type: models_opensearch::SearchEntityType::Chats,},diff --git a/rust/cloud-storage/document_cognition_service/src/api/chats/patch_chat.rs b/rust/cloud-storage/document_cognition_service/src/api/chats/patch_chat.rsindex fb4590cc73..aaa2bc3851 100644--- a/rust/cloud-storage/document_cognition_service/src/api/chats/patch_chat.rs+++ b/rust/cloud-storage/document_cognition_service/src/api/chats/patch_chat.rs@@ -124,7 +124,7 @@ async fn patch_chat_v2(.sqs_client.send_message_to_search_event_queue(sqs_client::search::SearchQueueMessage::UpdateEntityName(- sqs_client::search::name::UpdateEntityName {+ sqs_client::search::name::EntityName {entity_id: chat_id,entity_type: models_opensearch::SearchEntityType::Chats,},diff --git a/rust/cloud-storage/document_cognition_service/src/api/ws/chat_message/mod.rs b/rust/cloud-storage/document_cognition_service/src/api/ws/chat_message/mod.rsindex aa4d6121ac..71328a12bb 100644--- a/rust/cloud-storage/document_cognition_service/src/api/ws/chat_message/mod.rs+++ b/rust/cloud-storage/document_cognition_service/src/api/ws/chat_message/mod.rs@@ -33,7 +33,7 @@ use metering_service_client::{CreateUsageRecordRequest, OperationType, ServiceNause model::chat::{NewAttachment, NewChatMessage};use models_opensearch::SearchEntityType;use sqs_client::search::SearchQueueMessage;-use sqs_client::search::name::UpdateEntityName;+use sqs_client::search::name::EntityName;use std::sync::Arc;use tokio;use tokio::sync::mpsc::UnboundedSender;@@ -423,7 +423,7 @@ pub async fn handle_send_chat_message(match macro_uuid::string_to_uuid(&incoming_message.chat_id) {Ok(chat_id) => {let _ = ctx.sqs_client.send_message_to_search_event_queue(- SearchQueueMessage::UpdateEntityName(UpdateEntityName {+ SearchQueueMessage::UpdateEntityName(EntityName {entity_id: chat_id,entity_type: SearchEntityType::Chats,}),diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_document_handler.rs b/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_document_handler.rsindex b3b36f5f93..0b3f8c7a38 100644--- a/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_document_handler.rs+++ b/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_document_handler.rs@@ -5,7 +5,7 @@ use macro_middleware::cloud_storage::ensure_access::project::ProjectBodyAccessLeuse models_opensearch::SearchEntityType;use models_permissions::share_permission::access_level::EditAccessLevel;use sqs_client::search::SearchQueueMessage;-use sqs_client::search::name::UpdateEntityName;+use sqs_client::search::name::EntityName;use tracing::Instrument;use crate::api::middleware::internal_access::InternalUser;@@ -137,7 +137,7 @@ pub(in crate::api) async fn create_document_handler(let _ = sqs_client.send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(- UpdateEntityName {+ EntityName {entity_id: document_id,entity_type: SearchEntityType::Documents,},diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/edit_document/edit_document_v2.rs b/rust/cloud-storage/document_storage_service/src/api/documents/edit_document/edit_document_v2.rsindex 10b5ff123c..32093cdc37 100644--- a/rust/cloud-storage/document_storage_service/src/api/documents/edit_document/edit_document_v2.rs+++ b/rust/cloud-storage/document_storage_service/src/api/documents/edit_document/edit_document_v2.rs@@ -13,7 +13,7 @@ use model::{use models_opensearch::SearchEntityType;use models_permissions::share_permission::UpdateSharePermissionRequestV2;use models_permissions::share_permission::access_level::AccessLevel;-use sqs_client::search::{SearchQueueMessage, document::DocumentId, name::UpdateEntityName};+use sqs_client::search::{SearchQueueMessage, document::DocumentId, name::EntityName};use tracing::Instrument;pub async fn edit_document(@@ -99,7 +99,7 @@ pub async fn edit_document(let _ = sqs_client.send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(- UpdateEntityName {+ EntityName {entity_id: document_id,entity_type: SearchEntityType::Documents,},diff --git a/rust/cloud-storage/email_db_client/src/messages/delete.rs b/rust/cloud-storage/email_db_client/src/messages/delete.rsindex dc7de2b5a7..24a2412fac 100644--- a/rust/cloud-storage/email_db_client/src/messages/delete.rs+++ b/rust/cloud-storage/email_db_client/src/messages/delete.rs@@ -4,14 +4,15 @@ use models_email::email::service::message;use sqlx::types::Uuid;use sqlx::{Executor, Postgres};-/// Deletes message from the database with transaction handling. Returns if the thread was deleted+/// Deletes message from the database with transaction handling. Returns an optional db thread id+/// if the thread was deleted#[tracing::instrument(skip(tx, message), fields(link_id = %message.link_id), level = "info")]pub async fn delete_message_with_tx(tx: &mut sqlx::PgConnection,message: &message::SimpleMessage,// update thread-object vals (inbox_visible, latest timestamps)update_thread_metadata: bool,-) -> anyhow::Result<()> {+) -> anyhow::Result<Option<Uuid>> {// delete the message itselfdelete_db_message(&mut *tx, message.db_id).await@@ -28,7 +29,11 @@ pub async fn delete_message_with_tx(.context("Failed to update thread metadata")?;}- Ok(())+ if deleted_thread {+ Ok(Some(message.thread_db_id))+ } else {+ Ok(None)+ }}#[tracing::instrument(skip(executor), level = "info")]diff --git a/rust/cloud-storage/email_service/src/api/email/drafts/delete.rs b/rust/cloud-storage/email_service/src/api/email/drafts/delete.rsindex 7104eab711..0d1300e89b 100644--- a/rust/cloud-storage/email_service/src/api/email/drafts/delete.rs+++ b/rust/cloud-storage/email_service/src/api/email/drafts/delete.rs@@ -5,6 +5,9 @@ use axum::http::StatusCode;use axum::response::{IntoResponse, Response};use model::response::{EmptyResponse, ErrorResponse};use models_email::service::link::Link;+use models_opensearch::SearchEntityType;+use sqs_client::search::SearchQueueMessage;+use sqs_client::search::name::EntityName;use strum_macros::AsRefStr;use thiserror::Error;use uuid::Uuid;@@ -91,8 +94,26 @@ pub async fn handler(.await;match result {- Ok(_) => {+ Ok(deleted_thread) => {tx.commit().await?;++ if let Some(thread_id) = deleted_thread {+ tokio::spawn(async move {+ let _ = ctx+ .sqs_client+ .send_message_to_search_event_queue(SearchQueueMessage::RemoveEntityName(+ EntityName {+ entity_id: thread_id,+ entity_type: SearchEntityType::Emails,+ },+ ))+ .await+ .inspect_err(|e| {+ tracing::error!(error=?e, "failed to send message to search extractor queue");+ });+ });+ }+Ok(StatusCode::NO_CONTENT.into_response())}Err(e) => {diff --git a/rust/cloud-storage/email_service/src/api/email/sync/disable.rs b/rust/cloud-storage/email_service/src/api/email/sync/disable.rsindex d98e00faa5..3faa1c0d3b 100644--- a/rust/cloud-storage/email_service/src/api/email/sync/disable.rs+++ b/rust/cloud-storage/email_service/src/api/email/sync/disable.rs@@ -122,6 +122,7 @@ pub async fn disable_handler(.send_message_to_search_event_queue(SearchQueueMessage::RemoveEmailLink(EmailLinkMessage {link_id: link_context_cloned.id.to_string(),+ macro_user_id: link_context_cloned.macro_id.clone(),},)).awaitdiff --git a/rust/cloud-storage/email_service/src/api/internal/delete_user.rs b/rust/cloud-storage/email_service/src/api/internal/delete_user.rsindex b10bf2d41d..bc8b687e8d 100644--- a/rust/cloud-storage/email_service/src/api/internal/delete_user.rs+++ b/rust/cloud-storage/email_service/src/api/internal/delete_user.rs@@ -69,12 +69,14 @@ pub async fn handler(let db = ctx.db.clone();let sqs_client = ctx.sqs_client.clone();let link_id = link.id;+ let macro_user_id = link.macro_id;tokio::spawn(async move {// send message to search text extractor queuesqs_client.send_message_to_search_event_queue(SearchQueueMessage::RemoveEmailLink(EmailLinkMessage {link_id: link.id.to_string(),+ macro_user_id,},)).awaitdiff --git a/rust/cloud-storage/email_service/src/pubsub/backfill/update_metadata.rs b/rust/cloud-storage/email_service/src/pubsub/backfill/update_metadata.rsindex 4e5e6d6d43..ce6cec0aff 100644--- a/rust/cloud-storage/email_service/src/pubsub/backfill/update_metadata.rs+++ b/rust/cloud-storage/email_service/src/pubsub/backfill/update_metadata.rs@@ -6,7 +6,7 @@ use models_email::email::service::pubsub::{DetailedError, FailureReason, Processuse models_opensearch::SearchEntityType;use sqs_client::search::SearchQueueMessage;use sqs_client::search::email::EmailThreadMessage;-use sqs_client::search::name::UpdateEntityName;+use sqs_client::search::name::EntityName;/// This step is invoked by BackfillMessage once all messages in a thread have been backfilled./// Updates the thread metadata in the database, the replying_to_id values of its messages, and@@ -100,12 +100,10 @@ pub async fn update_thread_metadata(// notify search about new entityctx.sqs_client- .send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(- UpdateEntityName {- entity_id: p.thread_db_id,- entity_type: SearchEntityType::Emails,- },- ))+ .send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(EntityName {+ entity_id: p.thread_db_id,+ entity_type: SearchEntityType::Emails,+ })).await.map_err(|e| {ProcessingError::NonRetryable(DetailedError {diff --git a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/delete_message.rs b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/delete_message.rsindex d65f9cfce4..4ebd04226a 100644--- a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/delete_message.rs+++ b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/delete_message.rs@@ -3,9 +3,12 @@ use crate::pubsub::util::{cg_refresh_email, complete_transaction_with_processinguse models_email::email::service::link;use models_email::gmail::webhook::DeleteMessagePayload;use models_email::service::pubsub::{DetailedError, FailureReason, ProcessingError};+use models_opensearch::SearchEntityType;use sqs_client::search::SearchQueueMessage;use sqs_client::search::email::EmailMessage;+use sqs_client::search::name::EntityName;use std::result;+use uuid::Uuid;// delete user's message from the db#[tracing::instrument(skip(ctx))]@@ -42,18 +45,40 @@ pub async fn delete_message(})?;let result = async {- email_db_client::messages::delete::delete_message_with_tx(&mut tx, &message, true)- .await- .map_err(|e| {- ProcessingError::Retryable(DetailedError {- reason: FailureReason::DatabaseQueryFailed,- source: e.context("Failed to delete message with transaction".to_string()),- })- })?;- Ok::<(), ProcessingError>(())+ let result =+ email_db_client::messages::delete::delete_message_with_tx(&mut tx, &message, true)+ .await+ .map_err(|e| {+ ProcessingError::Retryable(DetailedError {+ reason: FailureReason::DatabaseQueryFailed,+ source: e.context("Failed to delete message with transaction".to_string()),+ })+ })?;+ Ok::<Option<Uuid>, ProcessingError>(result)}.await;+ if let Ok(deleted_thread) = result+ && let Some(thread_id) = deleted_thread+ {+ let sqs_client = ctx.sqs_client.clone();+ tokio::spawn({+ async move {+ let _ = sqs_client+ .send_message_to_search_event_queue(SearchQueueMessage::RemoveEntityName(+ EntityName {+ entity_id: thread_id,+ entity_type: SearchEntityType::Emails,+ },+ ))+ .await+ .inspect_err(|e| {+ tracing::error!(error=?e, "failed to send message to search extractor queue");+ });+ }+ });+ }+complete_transaction_with_processing_error(tx, result).await?;// tell FE to refresh user's inboxdiff --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.rsindex c26b353e7c..e9bfda820b 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@@ -27,7 +27,7 @@ use models_email::service::pubsub::{DetailedError, FailureReason, ProcessingErrouse models_opensearch::SearchEntityType;use sqs_client::search::SearchQueueMessage;use sqs_client::search::email::EmailMessage;-use sqs_client::search::name::UpdateEntityName;+use sqs_client::search::name::EntityName;use std::collections::{HashMap, HashSet};use std::result;use uuid::Uuid;@@ -428,12 +428,10 @@ async fn fetch_and_insert_thread(// notify search about new entityctx.sqs_client- .send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(- UpdateEntityName {- entity_id: thread_id,- entity_type: SearchEntityType::Emails,- },- ))+ .send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(EntityName {+ entity_id: thread_id,+ entity_type: SearchEntityType::Emails,+ })).await.map_err(|e| {ProcessingError::NonRetryable(DetailedError {diff --git a/rust/cloud-storage/opensearch_client/src/delete/mod.rs b/rust/cloud-storage/opensearch_client/src/delete/mod.rsindex 9beec20bd4..82ce8db5c7 100644--- a/rust/cloud-storage/opensearch_client/src/delete/mod.rs+++ b/rust/cloud-storage/opensearch_client/src/delete/mod.rs@@ -2,4 +2,5 @@ pub mod channel;pub mod chat;pub mod document;pub mod email;+pub mod name;pub mod project;diff --git a/rust/cloud-storage/opensearch_client/src/delete/name.rs b/rust/cloud-storage/opensearch_client/src/delete/name.rsnew file mode 100644index 0000000000..d378794bda--- /dev/null+++ b/rust/cloud-storage/opensearch_client/src/delete/name.rs@@ -0,0 +1,115 @@+use crate::{Result, error::ResponseExt};+use models_opensearch::{SearchEntityType, SearchIndex};++/// Deletes all name documents with the specified entity_id and entity_type+#[tracing::instrument(skip(client))]+pub async fn delete_entity_name(+ client: &opensearch::OpenSearch,+ entity_id: &str,+ entity_type: &SearchEntityType,+) -> Result<()> {+ let query = serde_json::json!({+ "query": {+ "bool": {+ "must": [+ {+ "term": {+ "entity_id": entity_id+ }+ },+ {+ "term": {+ "entity_type": entity_type.as_ref()+ }+ }+ ]+ }+ }+ });++ client+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Names.as_ref()+ ]))+ .body(query)+ .refresh(true) // Ensure the index reflects changes immediately+ .send()+ .await+ .map_client_error()+ .await?;++ Ok(())+}++/// Deletes all names for a specified set of entity_ids and an entity_type+pub async fn delete_entity_name_bulk(+ client: &opensearch::OpenSearch,+ entity_ids: &[String],+ entity_type: &SearchEntityType,+) -> Result<()> {+ let query = serde_json::json!({+ "query": {+ "bool": {+ "must": [+ {+ "terms": {+ "entity_id": entity_ids+ }+ },+ {+ "term": {+ "entity_type": entity_type.as_ref()+ }+ }+ ]+ }+ }+ });++ client+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Names.as_ref()+ ]))+ .body(query)+ .refresh(true) // Ensure the index reflects changes immediately+ .send()+ .await+ .map_client_error()+ .await?;++ Ok(())+}++/// Deletes all names for a specified user_id+#[tracing::instrument(skip(client))]+pub async fn delete_entity_name_bulk_for_user(+ client: &opensearch::OpenSearch,+ user_id: &str,+) -> Result<()> {+ let query = serde_json::json!({+ "query": {+ "bool": {+ "must": [+ {+ "term": {+ "user_id": user_id+ }+ }+ ]+ }+ }+ });++ client+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Names.as_ref()+ ]))+ .body(query)+ .refresh(true) // Ensure the index reflects changes immediately+ .send()+ .await+ .map_client_error()+ .await?;++ Ok(())+}diff --git a/rust/cloud-storage/opensearch_client/src/name.rs b/rust/cloud-storage/opensearch_client/src/name.rsindex ab8b950411..e216e3c9f3 100644--- a/rust/cloud-storage/opensearch_client/src/name.rs+++ b/rust/cloud-storage/opensearch_client/src/name.rs@@ -1,5 +1,8 @@+use models_opensearch::SearchEntityType;+use crate::{OpensearchClient, Result,+ delete::name::{delete_entity_name, delete_entity_name_bulk, delete_entity_name_bulk_for_user},upsert::name::{UpsertEntityNameArgs, upsert_entity_name},};@@ -9,4 +12,30 @@ impl OpensearchClient {pub async fn upsert_entity_name(&self, args: &UpsertEntityNameArgs) -> Result<()> {upsert_entity_name(&self.inner, args).await}++ /// Delete entity name+ #[tracing::instrument(skip(self), err)]+ pub async fn delete_entity_name(+ &self,+ entity_id: &str,+ entity_type: &SearchEntityType,+ ) -> Result<()> {+ delete_entity_name(&self.inner, entity_id, entity_type).await+ }++ /// Delete entity names bulk+ #[tracing::instrument(skip(self), err)]+ pub async fn delete_entity_names_bulk(+ &self,+ entity_ids: &[String],+ entity_type: &SearchEntityType,+ ) -> Result<()> {+ delete_entity_name_bulk(&self.inner, entity_ids, entity_type).await+ }++ /// Delete entity names for a user+ #[tracing::instrument(skip(self), err)]+ pub async fn delete_entities_for_user(&self, user_id: &str) -> Result<()> {+ delete_entity_name_bulk_for_user(&self.inner, user_id).await+ }}diff --git a/rust/cloud-storage/search_processing_service/Cargo.toml b/rust/cloud-storage/search_processing_service/Cargo.tomlindex d1413ae800..249829df20 100644--- a/rust/cloud-storage/search_processing_service/Cargo.toml+++ b/rust/cloud-storage/search_processing_service/Cargo.toml@@ -70,3 +70,4 @@ tracing = { workspace = true }utoipa = { workspace = true }utoipa-swagger-ui = { workspace = true }uuid = { workspace = true }+models_opensearch = { path = "../models_opensearch" }diff --git a/rust/cloud-storage/search_processing_service/src/process/chat.rs b/rust/cloud-storage/search_processing_service/src/process/chat.rsindex 583e91b4af..506018c32d 100644--- a/rust/cloud-storage/search_processing_service/src/process/chat.rs+++ b/rust/cloud-storage/search_processing_service/src/process/chat.rs@@ -1,4 +1,5 @@use anyhow::Context;+use models_opensearch::SearchEntityType;use opensearch_client::{OpensearchClient, date_format::EpochSeconds, upsert::chat_message::UpsertChatMessageArgs,};@@ -54,6 +55,10 @@ pub async fn remove_chat_message(opensearch_client.delete_chat(remove_message.chat_id.as_str()).await?;++ opensearch_client+ .delete_entity_name(remove_message.chat_id.as_str(), &SearchEntityType::Chats)+ .await?;}Ok(())diff --git a/rust/cloud-storage/search_processing_service/src/process/document/mod.rs b/rust/cloud-storage/search_processing_service/src/process/document/mod.rsindex e37c3268e7..ce5a767e94 100644--- a/rust/cloud-storage/search_processing_service/src/process/document/mod.rs+++ b/rust/cloud-storage/search_processing_service/src/process/document/mod.rs@@ -1,5 +1,6 @@use anyhow::Context;use model::document::FileTypeExt;+use models_opensearch::SearchEntityType;use opensearch_client::OpensearchClient;use sqs_client::search::document::{DocumentId, SearchExtractorMessage};@@ -14,6 +15,13 @@ pub async fn process_remove_message(.delete_document(remove_message.document_id.as_str()).await?;+ opensearch_client+ .delete_entity_name(+ remove_message.document_id.as_str(),+ &SearchEntityType::Documents,+ )+ .await?;+Ok(())}diff --git a/rust/cloud-storage/search_processing_service/src/process/email/remove.rs b/rust/cloud-storage/search_processing_service/src/process/email/remove.rsindex e68424e47f..48c8b74fe7 100644--- a/rust/cloud-storage/search_processing_service/src/process/email/remove.rs+++ b/rust/cloud-storage/search_processing_service/src/process/email/remove.rs@@ -20,5 +20,9 @@ pub async fn process_remove_messages_by_link_id(.delete_email_messages_by_link_id(remove_link_message.link_id.as_str()).await?;+ opensearch_client+ .delete_entities_for_user(remove_link_message.macro_user_id.as_str())+ .await?;+Ok(())}diff --git a/rust/cloud-storage/search_processing_service/src/process/mod.rs b/rust/cloud-storage/search_processing_service/src/process/mod.rsindex ecc618dec9..5e387ac200 100644--- a/rust/cloud-storage/search_processing_service/src/process/mod.rs+++ b/rust/cloud-storage/search_processing_service/src/process/mod.rs@@ -36,6 +36,9 @@ pub async fn process_message(SearchQueueMessage::UpdateEntityName(message) => {name::upsert_name(&ctx.opensearch_client, &ctx.db, &message).await?;}+ SearchQueueMessage::RemoveEntityName(message) => {+ name::remove_name(&ctx.opensearch_client, &message).await?;+ }SearchQueueMessage::RemoveUserProfile(user_profile_id) => {tracing::trace!(user_profile_id = user_profile_id, "removing user profile");user::remove_user_profile(&ctx.opensearch_client, &user_profile_id).await?;diff --git a/rust/cloud-storage/search_processing_service/src/process/name.rs b/rust/cloud-storage/search_processing_service/src/process/name.rsindex 180efa8c46..6838fd48d6 100644--- a/rust/cloud-storage/search_processing_service/src/process/name.rs+++ b/rust/cloud-storage/search_processing_service/src/process/name.rs@@ -1,14 +1,14 @@//! This module handles the processing of entity name messagesuse opensearch_client::{OpensearchClient, upsert::name::UpsertEntityNameArgs};-use sqs_client::search::name::UpdateEntityName;+use sqs_client::search::name::EntityName;/// Handles upserting the name for an entity#[tracing::instrument(skip(opensearch_client, db), err)]pub async fn upsert_name(opensearch_client: &OpensearchClient,db: &sqlx::Pool<sqlx::Postgres>,- message: &UpdateEntityName,+ message: &EntityName,) -> anyhow::Result<()> {let (entity_name, user_id) = macro_db_client::entity_name::get_entity_name_and_owner(db,@@ -39,3 +39,16 @@ pub async fn upsert_name(Ok(())}++/// Handles removing the name for an entity+#[tracing::instrument(skip(opensearch_client), err)]+pub async fn remove_name(+ opensearch_client: &OpensearchClient,+ message: &EntityName,+) -> anyhow::Result<()> {+ opensearch_client+ .delete_entity_name(&message.entity_id.to_string(), &message.entity_type)+ .await?;++ Ok(())+}diff --git a/rust/cloud-storage/search_processing_service/src/process/user.rs b/rust/cloud-storage/search_processing_service/src/process/user.rsindex 717168a61a..b71d723ffd 100644--- a/rust/cloud-storage/search_processing_service/src/process/user.rs+++ b/rust/cloud-storage/search_processing_service/src/process/user.rs@@ -9,9 +9,6 @@ pub async fn remove_user_profile(anyhow::bail!("user id must start with `macro|`");}- // NOTE: we do not delete channel messages from user as channel messages are preserved after a- // user profile has been removed.-// Delete documents of useropensearch_client.delete_documents_by_owner_id(user_profile_id)@@ -32,6 +29,9 @@ pub async fn remove_user_profile(.delete_projects_by_user_id(user_profile_id).await?;- // Validate the user id is `macro|${email}`+ opensearch_client+ .delete_entities_for_user(user_profile_id)+ .await?;+Ok(())}diff --git a/rust/cloud-storage/sqs_client/src/search/email.rs b/rust/cloud-storage/sqs_client/src/search/email.rsindex 5ed0cce038..547f027ab1 100644--- a/rust/cloud-storage/sqs_client/src/search/email.rs+++ b/rust/cloud-storage/sqs_client/src/search/email.rs@@ -18,4 +18,6 @@ pub struct EmailThreadMessage {pub struct EmailLinkMessage {/// The link idpub link_id: String,+ /// The macro user id associated with the link+ pub macro_user_id: String,}diff --git a/rust/cloud-storage/sqs_client/src/search/mod.rs b/rust/cloud-storage/sqs_client/src/search/mod.rsindex 455ab87143..258bbd949d 100644--- a/rust/cloud-storage/sqs_client/src/search/mod.rs+++ b/rust/cloud-storage/sqs_client/src/search/mod.rs@@ -5,7 +5,7 @@ use crate::{chat::{ChatMessage, RemoveChatMessage, UpdateChatMessageMetadata},document::{DocumentId, SearchExtractorMessage},email::{EmailLinkMessage, EmailMessage, EmailThreadMessage},- name::UpdateEntityName,+ name::EntityName,project::{BulkRemoveProjectMessage, ProjectMessage},},};@@ -93,7 +93,8 @@ pub enum SearchQueueMessage {RemoveUserProfile(String),// Entity Name- UpdateEntityName(UpdateEntityName),+ UpdateEntityName(EntityName),+ RemoveEntityName(EntityName),}impl PrimaryId for SearchQueueMessage {@@ -127,7 +128,9 @@ impl PrimaryId for SearchQueueMessage {SearchQueueMessage::BulkRemoveProjectMessage(message) => message.project_ids[0].clone(),SearchQueueMessage::RemoveUserProfile(message) => message.clone(),- SearchQueueMessage::UpdateEntityName(message) => message.entity_id.to_string(),++ SearchQueueMessage::UpdateEntityName(message)+ | SearchQueueMessage::RemoveEntityName(message) => message.entity_id.to_string(),}}}@@ -160,6 +163,7 @@ impl SearchQueueMessage {SearchQueueMessage::RemoveUserProfile(_) => Operation::Remove,// Entity NameSearchQueueMessage::UpdateEntityName(_) => Operation::UpdateMetadata,+ SearchQueueMessage::RemoveEntityName(_) => Operation::Remove,}}}diff --git a/rust/cloud-storage/sqs_client/src/search/name.rs b/rust/cloud-storage/sqs_client/src/search/name.rsindex 63d39fcaed..d60b65a7b3 100644--- a/rust/cloud-storage/sqs_client/src/search/name.rs+++ b/rust/cloud-storage/sqs_client/src/search/name.rs@@ -4,7 +4,7 @@ use models_opensearch::SearchEntityType;/// Sent to SPS via a queue for processing to update the names index with the new name/// of the entity#[derive(serde::Serialize, serde::Deserialize, PartialEq, Eq, Debug)]-pub struct UpdateEntityName {+pub struct EntityName {pub entity_id: uuid::Uuid,pub entity_type: SearchEntityType,}