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(search): Add in email snippet to enriched email search data (#117)

Will Hutchinson4b4e394cc9db
diff --git a/rust/cloud-storage/email_db_client/.sqlx/query-a8be0e96e672b9f0b0e79f39de6bae2f07a08f35b25d7046ba2c204535974006.json b/rust/cloud-storage/email_db_client/.sqlx/query-120abddd2c7bae7372351b33e7809f5141da3adcd699fcbd5b38a2aa7b81062a.json
similarity index 62%
rename from rust/cloud-storage/email_db_client/.sqlx/query-a8be0e96e672b9f0b0e79f39de6bae2f07a08f35b25d7046ba2c204535974006.json
rename to rust/cloud-storage/email_db_client/.sqlx/query-120abddd2c7bae7372351b33e7809f5141da3adcd699fcbd5b38a2aa7b81062a.json
index ec51f1869a..f5c7f9548f 100644
--- a/rust/cloud-storage/email_db_client/.sqlx/query-a8be0e96e672b9f0b0e79f39de6bae2f07a08f35b25d7046ba2c204535974006.json
+++ b/rust/cloud-storage/email_db_client/.sqlx/query-120abddd2c7bae7372351b33e7809f5141da3adcd699fcbd5b38a2aa7b81062a.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n m.thread_id,\n MIN(m.created_at) as \"earliest_created_at!\",\n MAX(m.created_at) as \"latest_updated_at!\",\n uh.updated_at as \"viewed_at?\"\n FROM email_messages m\n LEFT JOIN email_user_history uh ON uh.thread_id = m.thread_id AND uh.link_id = $1\n WHERE m.thread_id = ANY($2)\n AND m.link_id = $1\n GROUP BY m.thread_id, uh.updated_at\n ",
+ "query": "\n SELECT\n m.thread_id,\n MIN(m.created_at) as \"earliest_created_at!\",\n MAX(m.created_at) as \"latest_updated_at!\",\n uh.updated_at as \"viewed_at?\",\n m.snippet\n FROM email_messages m\n LEFT JOIN email_user_history uh ON uh.thread_id = m.thread_id AND uh.link_id = $1\n WHERE m.thread_id = ANY($2)\n AND m.link_id = $1\n GROUP BY m.thread_id, uh.updated_at, m.snippet\n ",
"describe": {
"columns": [
{
@@ -22,6 +22,11 @@
"ordinal": 3,
"name": "viewed_at?",
"type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 4,
+ "name": "snippet",
+ "type_info": "Text"
}
],
"parameters": {
@@ -34,8 +39,9 @@
false,
null,
null,
- false
+ false,
+ true
]
},
- "hash": "a8be0e96e672b9f0b0e79f39de6bae2f07a08f35b25d7046ba2c204535974006"
+ "hash": "120abddd2c7bae7372351b33e7809f5141da3adcd699fcbd5b38a2aa7b81062a"
}
diff --git a/rust/cloud-storage/email_db_client/src/user_history/mod.rs b/rust/cloud-storage/email_db_client/src/user_history/mod.rs
index d668839a9e..9aae68ade3 100644
--- a/rust/cloud-storage/email_db_client/src/user_history/mod.rs
+++ b/rust/cloud-storage/email_db_client/src/user_history/mod.rs
@@ -29,9 +29,9 @@ pub async fn upsert_user_history(
Ok(())
}
-// get history info for threads. created_at is when the first message was created, updated_at is when
-// the latest message was created, viewed_at is the last time the thread was opened by the user
-#[tracing::instrument(skip(pool), level = "info")]
+/// get history info for threads. created_at is when the first message was created, updated_at is when
+/// the latest message was created, viewed_at is the last time the thread was opened by the user
+#[tracing::instrument(skip(pool), err)]
pub async fn get_thread_summary_info(
pool: &PgPool,
link_id: Uuid,
@@ -47,12 +47,13 @@ pub async fn get_thread_summary_info(
m.thread_id,
MIN(m.created_at) as "earliest_created_at!",
MAX(m.created_at) as "latest_updated_at!",
- uh.updated_at as "viewed_at?"
+ uh.updated_at as "viewed_at?",
+ m.snippet
FROM email_messages m
LEFT JOIN email_user_history uh ON uh.thread_id = m.thread_id AND uh.link_id = $1
WHERE m.thread_id = ANY($2)
AND m.link_id = $1
- GROUP BY m.thread_id, uh.updated_at
+ GROUP BY m.thread_id, uh.updated_at, m.snippet
"#,
link_id,
thread_ids
@@ -66,6 +67,7 @@ pub async fn get_thread_summary_info(
for row in rows {
let summary_info = ThreadHistoryInfo {
item_id: row.thread_id,
+ snippet: row.snippet,
created_at: row.earliest_created_at,
updated_at: row.latest_updated_at,
viewed_at: row.viewed_at.and_then(|viewed| {
diff --git a/rust/cloud-storage/models_email/src/email/service/message.rs b/rust/cloud-storage/models_email/src/email/service/message.rs
index 4301d26604..0605822796 100644
--- a/rust/cloud-storage/models_email/src/email/service/message.rs
+++ b/rust/cloud-storage/models_email/src/email/service/message.rs
@@ -307,6 +307,7 @@ pub struct ThreadHistoryInfo {
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub viewed_at: Option<DateTime<Utc>>,
+ pub snippet: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
diff --git a/rust/cloud-storage/models_search/src/email.rs b/rust/cloud-storage/models_search/src/email.rs
index 84549f5bf8..5344fdab0e 100644
--- a/rust/cloud-storage/models_search/src/email.rs
+++ b/rust/cloud-storage/models_search/src/email.rs
@@ -51,6 +51,7 @@ pub struct EmailSearchResponseItemWithMetadata {
pub created_at: i64,
pub updated_at: i64,
pub viewed_at: Option<i64>,
+ pub snippet: Option<String>,
#[serde(flatten)]
pub extra: EmailSearchResponseItem,
}
diff --git a/rust/cloud-storage/search_service/src/api/search/email.rs b/rust/cloud-storage/search_service/src/api/search/email.rs
index 59aca2b22e..6399bbc4a0 100644
--- a/rust/cloud-storage/search_service/src/api/search/email.rs
+++ b/rust/cloud-storage/search_service/src/api/search/email.rs
@@ -121,6 +121,7 @@ pub fn construct_search_result(
created_at: message_history_info.created_at.timestamp(),
updated_at: message_history_info.updated_at.timestamp(),
viewed_at: message_history_info.viewed_at.map(|a| a.timestamp()),
+ snippet: message_history_info.snippet,
extra: item,
}
})