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.

chore(search): remove unused names index client code (#2702)

gbirmanc8107bfbf19d
diff --git a/infra/stacks/opensearch/helpers/scripts/delete_user_entities.ts b/infra/stacks/opensearch/helpers/scripts/delete_user_entities.ts
index 970fa41eff..7ef3875d05 100644
--- a/infra/stacks/opensearch/helpers/scripts/delete_user_entities.ts
+++ b/infra/stacks/opensearch/helpers/scripts/delete_user_entities.ts
@@ -99,7 +99,6 @@ async function deleteUserData() {
`Found ${docCount} documents with user_id OR owner_id: ${userId} in ${index}`
);
- // even if no documents exist, still check the names index for any to delete
if (docCount === 0) {
console.log(`No documents to delete in ${index}`);
} else {
diff --git a/rust/cloud-storage/models_opensearch/src/lib.rs b/rust/cloud-storage/models_opensearch/src/lib.rs
index 18838dff19..3fb023b907 100644
--- a/rust/cloud-storage/models_opensearch/src/lib.rs
+++ b/rust/cloud-storage/models_opensearch/src/lib.rs
@@ -16,8 +16,6 @@ pub enum SearchIndex {
/// The email index
#[strum(serialize = "emails_alias")]
Emails,
- /// The name index
- Names,
}
/// All searchable entity types across the system.
diff --git a/rust/cloud-storage/opensearch_client/src/delete/mod.rs b/rust/cloud-storage/opensearch_client/src/delete/mod.rs
index fd69901855..0f40840c1b 100644
--- a/rust/cloud-storage/opensearch_client/src/delete/mod.rs
+++ b/rust/cloud-storage/opensearch_client/src/delete/mod.rs
@@ -2,4 +2,3 @@ pub mod channel;
pub mod chat;
pub mod document;
pub mod email;
-pub mod name;
diff --git a/rust/cloud-storage/opensearch_client/src/delete/name.rs b/rust/cloud-storage/opensearch_client/src/delete/name.rs
deleted file mode 100644
index 2667d024f1..0000000000
--- a/rust/cloud-storage/opensearch_client/src/delete/name.rs
+++ /dev/null
@@ -1,155 +0,0 @@
-use crate::{Result, error::ResponseExt};
-use models_opensearch::{OpenSearchEntityType, 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: &OpenSearchEntityType,
-) -> 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: &OpenSearchEntityType,
-) -> 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(())
-}
-
-/// Deletes all names for a specified user_id and entity_type
-#[tracing::instrument(skip(client), err)]
-pub async fn delete_entity_name_bulk_for_user_by_entity_type(
- client: &opensearch::OpenSearch,
- user_id: &str,
- entity_type: &OpenSearchEntityType,
-) -> Result<()> {
- let query = serde_json::json!({
- "query": {
- "bool": {
- "must": [
- {
- "term": {
- "user_id": user_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(())
-}
diff --git a/rust/cloud-storage/opensearch_client/src/lib.rs b/rust/cloud-storage/opensearch_client/src/lib.rs
index b8485c9109..9ce9123b30 100644
--- a/rust/cloud-storage/opensearch_client/src/lib.rs
+++ b/rust/cloud-storage/opensearch_client/src/lib.rs
@@ -1,7 +1,6 @@
pub mod date_format;
pub mod delete;
pub mod error;
-pub mod name;
pub mod search;
pub mod unified;
pub mod upsert;
diff --git a/rust/cloud-storage/opensearch_client/src/name.rs b/rust/cloud-storage/opensearch_client/src/name.rs
deleted file mode 100644
index cc0672c02b..0000000000
--- a/rust/cloud-storage/opensearch_client/src/name.rs
+++ /dev/null
@@ -1,54 +0,0 @@
-use models_opensearch::OpenSearchEntityType;
-
-use crate::{
- OpensearchClient, Result,
- delete::name::{
- delete_entity_name, delete_entity_name_bulk, delete_entity_name_bulk_for_user,
- delete_entity_name_bulk_for_user_by_entity_type,
- },
- upsert::name::{UpsertEntityNameArgs, upsert_entity_name},
-};
-
-impl OpensearchClient {
- /// Upserts an entity name into the opensearch index
- #[tracing::instrument(skip(self), err)]
- 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: &OpenSearchEntityType,
- ) -> 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: &OpenSearchEntityType,
- ) -> 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
- }
-
- /// Delete entity names for a user
- #[tracing::instrument(skip(self), err)]
- pub async fn delete_entities_for_user_by_entity_type(
- &self,
- user_id: &str,
- entity_type: &OpenSearchEntityType,
- ) -> Result<()> {
- delete_entity_name_bulk_for_user_by_entity_type(&self.inner, user_id, entity_type).await
- }
-}
diff --git a/rust/cloud-storage/opensearch_client/src/upsert/mod.rs b/rust/cloud-storage/opensearch_client/src/upsert/mod.rs
index 3ba451666d..a21975c497 100644
--- a/rust/cloud-storage/opensearch_client/src/upsert/mod.rs
+++ b/rust/cloud-storage/opensearch_client/src/upsert/mod.rs
@@ -2,7 +2,6 @@ pub mod channel_message;
pub mod chat_message;
pub mod document;
pub mod email;
-pub mod name;
use crate::error::OpensearchClientError;
diff --git a/rust/cloud-storage/opensearch_client/src/upsert/name.rs b/rust/cloud-storage/opensearch_client/src/upsert/name.rs
deleted file mode 100644
index c93b8650f2..0000000000
--- a/rust/cloud-storage/opensearch_client/src/upsert/name.rs
+++ /dev/null
@@ -1,39 +0,0 @@
-//! This module handles the upserting of entity names into the opensearch index
-
-use models_opensearch::{OpenSearchEntityType, SearchIndex};
-
-use crate::{Result, error::ResponseExt};
-
-/// The arguments for upserting an entity name into the opensearch index
-#[derive(Debug, serde::Serialize)]
-pub struct UpsertEntityNameArgs {
- /// The entity id
- pub entity_id: String,
- /// The macro user id who created the entity
- pub user_id: String,
- /// The entity name
- pub name: String,
- /// The entity type
- pub entity_type: OpenSearchEntityType,
-}
-
-#[tracing::instrument(skip(client), err)]
-pub(crate) async fn upsert_entity_name(
- client: &opensearch::OpenSearch,
- args: &UpsertEntityNameArgs,
-) -> Result<()> {
- client
- .index(opensearch::IndexParts::IndexId(
- SearchIndex::Names.as_ref(),
- &args.entity_id,
- ))
- .body(args)
- .send()
- .await
- .map_client_error()
- .await?;
-
- tracing::trace!(id=%args.entity_id, "entity name upserted successfully");
-
- Ok(())
-}
diff --git a/rust/cloud-storage/search_processing_service/src/process/chat.rs b/rust/cloud-storage/search_processing_service/src/process/chat.rs
index 5cd3083a19..bb54da49fd 100644
--- a/rust/cloud-storage/search_processing_service/src/process/chat.rs
+++ b/rust/cloud-storage/search_processing_service/src/process/chat.rs
@@ -1,5 +1,4 @@
use anyhow::Context;
-use models_opensearch::OpenSearchEntityType;
use opensearch_client::{
OpensearchClient, date_format::EpochSeconds, upsert::chat_message::UpsertChatMessageArgs,
};
@@ -55,13 +54,6 @@ 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(),
- &OpenSearchEntityType::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.rs
index 139d71ce58..84a9862730 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,6 +1,5 @@
use anyhow::Context;
use model::document::FileTypeExt;
-use models_opensearch::OpenSearchEntityType;
use opensearch_client::OpensearchClient;
use sqs_client::search::document::{DocumentId, SearchExtractorMessage};
@@ -15,13 +14,6 @@ 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(),
- &OpenSearchEntityType::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.rs
index 4c456eca10..e68424e47f 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
@@ -1,4 +1,3 @@
-use models_opensearch::OpenSearchEntityType;
use opensearch_client::OpensearchClient;
use sqs_client::search::email::{EmailLinkMessage, EmailMessage};
@@ -21,12 +20,5 @@ 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_by_entity_type(
- remove_link_message.macro_user_id.as_str(),
- &OpenSearchEntityType::Emails,
- )
- .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.rs
index df90ee9615..f876061152 100644
--- a/rust/cloud-storage/search_processing_service/src/process/user.rs
+++ b/rust/cloud-storage/search_processing_service/src/process/user.rs
@@ -24,9 +24,5 @@ pub async fn remove_user_profile(
.delete_email_messages_by_user_id(user_profile_id)
.await?;
- opensearch_client
- .delete_entities_for_user(user_profile_id)
- .await?;
-
Ok(())
}