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(soup): multi-inbox support via link_ids and Owner literal (#3636)

gbirman4c49ff0c2227
diff --git a/js/app/packages/app/component/next-soup/filters/filter-store/compile.ts b/js/app/packages/app/component/next-soup/filters/filter-store/compile.ts
index 6074dc4cc9..f624e43c0f 100644
--- a/js/app/packages/app/component/next-soup/filters/filter-store/compile.ts
+++ b/js/app/packages/app/component/next-soup/filters/filter-store/compile.ts
@@ -81,6 +81,7 @@ const FIELD_CONFIG: Record<
documentDone: { target: 'df', field: 'nd' },
isEmailAttachment: { target: 'df', field: 'iea' },
threadId: { target: 'ef', field: 'ThreadId' },
+ emailLinkId: { target: 'ef', field: 'Owner' },
emailSeen: { target: 'ef', field: 'NotificationSeen' },
emailDone: { target: 'ef', field: 'NotificationDone' },
emailImportance: { target: 'ef', field: 'Importance' },
diff --git a/js/app/packages/app/component/next-soup/filters/filter-store/types.ts b/js/app/packages/app/component/next-soup/filters/filter-store/types.ts
index 6f287c9c8c..460128f0dc 100644
--- a/js/app/packages/app/component/next-soup/filters/filter-store/types.ts
+++ b/js/app/packages/app/component/next-soup/filters/filter-store/types.ts
@@ -21,6 +21,7 @@ export type ArrayFieldFilters = {
projectId?: string[];
documentOwnerId?: string[];
threadId?: string[];
+ emailLinkId?: string[];
emailProjectId?: string[];
emailSender?: string[];
channelId?: string[];
diff --git a/js/app/packages/service-clients/service-search/generated/models/emailFilters.ts b/js/app/packages/service-clients/service-search/generated/models/emailFilters.ts
index 34002101e0..0746d5c97c 100644
--- a/js/app/packages/service-clients/service-search/generated/models/emailFilters.ts
+++ b/js/app/packages/service-clients/service-search/generated/models/emailFilters.ts
@@ -47,6 +47,9 @@ Note: SPAM and TRASH emails are not indexed in OpenSearch, so they are already e
/** Only include emails that have at least one of these labels. Supports both Gmail system labels (e.g. "INBOX", "CATEGORY_PROMOTIONS") and user-created labels (e.g. "github"). Empty to not filter by included labels.
Note: SPAM and TRASH emails are not indexed in OpenSearch, so they will never appear in results regardless of this filter. */
include_labels?: string[];
+ /** Restrict to specific inboxes by email_links.id. Empty means "any inbox the
+caller can access" (soup expands to the full set at the router edge). */
+ link_ids?: string[];
/** Filter by email notification state. */
notification_filters?: NotificationFilters;
/** A list of project ids to search within. Empty to ignore project filtering. */
diff --git a/js/app/packages/service-clients/service-search/openapi.json b/js/app/packages/service-clients/service-search/openapi.json
index 0540cd2e85..6e10a3a0f4 100644
--- a/js/app/packages/service-clients/service-search/openapi.json
+++ b/js/app/packages/service-clients/service-search/openapi.json
@@ -1168,6 +1168,13 @@
},
"description": "Only include emails that have at least one of these labels. Supports both Gmail system labels (e.g. \"INBOX\", \"CATEGORY_PROMOTIONS\") and user-created labels (e.g. \"github\"). Empty to not filter by included labels.\nNote: SPAM and TRASH emails are not indexed in OpenSearch, so they will never appear in results regardless of this filter."
},
+ "link_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "description": "Restrict to specific inboxes by email_links.id. Empty means \"any inbox the\ncaller can access\" (soup expands to the full set at the router edge)."
+ },
"notification_filters": {
"$ref": "#/components/schemas/NotificationFilters",
"description": "Filter by email notification state."
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/emailFilters.ts b/js/app/packages/service-clients/service-storage/generated/schemas/emailFilters.ts
index b2bfadfcee..9272694702 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/emailFilters.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/emailFilters.ts
@@ -47,6 +47,9 @@ Note: SPAM and TRASH emails are not indexed in OpenSearch, so they are already e
/** Only include emails that have at least one of these labels. Supports both Gmail system labels (e.g. "INBOX", "CATEGORY_PROMOTIONS") and user-created labels (e.g. "github"). Empty to not filter by included labels.
Note: SPAM and TRASH emails are not indexed in OpenSearch, so they will never appear in results regardless of this filter. */
include_labels?: string[];
+ /** Restrict to specific inboxes by email_links.id. Empty means "any inbox the
+caller can access" (soup expands to the full set at the router edge). */
+ link_ids?: string[];
/** Filter by email notification state. */
notification_filters?: NotificationFilters;
/** A list of project ids to search within. Empty to ignore project filtering. */
diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.ts
index fa091f58bd..4a2354bef0 100644
--- a/js/app/packages/service-clients/service-storage/generated/zod.ts
+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts
@@ -7458,6 +7458,12 @@ export const postItemsSoupBody = zod
.describe(
'Only include emails that have at least one of these labels. Supports both Gmail system labels (e.g. \"INBOX\", \"CATEGORY_PROMOTIONS\") and user-created labels (e.g. \"github\"). Empty to not filter by included labels.\nNote: SPAM and TRASH emails are not indexed in OpenSearch, so they will never appear in results regardless of this filter.'
),
+ link_ids: zod
+ .array(zod.string())
+ .optional()
+ .describe(
+ 'Restrict to specific inboxes by email_links.id. Empty means \"any inbox the\ncaller can access\" (soup expands to the full set at the router edge).'
+ ),
notification_filters: zod
.object({
done: zod
diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.json
index f52b055715..ddea1d055c 100644
--- a/js/app/packages/service-clients/service-storage/openapi.json
+++ b/js/app/packages/service-clients/service-storage/openapi.json
@@ -12062,6 +12062,13 @@
},
"description": "Only include emails that have at least one of these labels. Supports both Gmail system labels (e.g. \"INBOX\", \"CATEGORY_PROMOTIONS\") and user-created labels (e.g. \"github\"). Empty to not filter by included labels.\nNote: SPAM and TRASH emails are not indexed in OpenSearch, so they will never appear in results regardless of this filter."
},
+ "link_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "description": "Restrict to specific inboxes by email_links.id. Empty means \"any inbox the\ncaller can access\" (soup expands to the full set at the router edge)."
+ },
"notification_filters": {
"$ref": "#/components/schemas/NotificationFilters",
"description": "Filter by email notification state."
diff --git a/rust/cloud-storage/.sqlx/query-26dea63de88041b56c6a105b66cb71cb35883ece0f9928887b7ed5d628fe6696.json b/rust/cloud-storage/.sqlx/query-26dea63de88041b56c6a105b66cb71cb35883ece0f9928887b7ed5d628fe6696.json
new file mode 100644
index 0000000000..10930d913b
--- /dev/null
+++ b/rust/cloud-storage/.sqlx/query-26dea63de88041b56c6a105b66cb71cb35883ece0f9928887b7ed5d628fe6696.json
@@ -0,0 +1,122 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH trash_labels AS (\n SELECT id, link_id FROM email_labels WHERE link_id = ANY($1) AND name = 'TRASH'\n ),\n important_labels AS (\n SELECT id, link_id FROM email_labels WHERE link_id = ANY($1) AND name = 'IMPORTANT'\n )\n SELECT\n t.id,\n t.provider_id,\n TRUE AS \"inbox_visible!\",\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n JOIN important_labels il ON ml.label_id = il.id\n WHERE m_imp.thread_id = t.id\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Efficiently find and sort ONLY the top N+1 candidate threads.\n -- This subquery is fast as it only touches `threads` and `user_history`.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.is_read,\n t.project_id,\n t.latest_inbound_message_ts AS created_at,\n t.latest_inbound_message_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_inbound_message_ts)\n ELSE t.latest_inbound_message_ts\n END AS effective_ts\n FROM email_threads t\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n t.link_id = ANY($1)\n AND t.inbox_visible = TRUE\n AND t.latest_inbound_message_ts IS NOT NULL\n\n -- The cursor logic is moved inside this subquery for maximum efficiency.\n AND (($3::timestamptz IS NULL) OR (\n -- This CASE must exactly match the one that defines `effective_ts`\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_inbound_message_ts)\n ELSE t.latest_inbound_message_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC -- fall back to updated_at if effective_ts is the same\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find its latest non-trashed message.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name,\n m.is_draft\n FROM email_messages m\n WHERE m.thread_id = t.id\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n JOIN trash_labels tl ON ml.label_id = tl.id\n WHERE ml.message_id = m.id\n )\n ORDER BY m.internal_date_ts DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details for the final result set.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n -- Final ordering is preserved because the input `t` is already sorted.\n ORDER BY t.effective_ts DESC, t.updated_at DESC -- fall back to updated_at if effective_ts is the same\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "provider_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "inbox_visible!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 3,
+ "name": "is_read",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 4,
+ "name": "sort_ts!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "viewed_at?",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "name?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 10,
+ "name": "snippet?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 11,
+ "name": "is_draft",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 12,
+ "name": "is_important!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 13,
+ "name": "sender_email?",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 14,
+ "name": "sender_name?",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 15,
+ "name": "sender_photo_url?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 16,
+ "name": "owner_id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "Int8",
+ "Timestamptz",
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ null,
+ false,
+ null,
+ true,
+ true,
+ true,
+ false,
+ true,
+ true,
+ false,
+ null,
+ false,
+ null,
+ true,
+ false
+ ]
+ },
+ "hash": "26dea63de88041b56c6a105b66cb71cb35883ece0f9928887b7ed5d628fe6696"
+}
diff --git a/rust/cloud-storage/.sqlx/query-82301526394304e59946caa3c724c377fa46ad214834bc1a876d39ad29ad92ac.json b/rust/cloud-storage/.sqlx/query-3fdecaafcd87b6e4776cdc7aeb36e46b5a0410a1229f53886035fd0fd1d88a63.json
similarity index 68%
rename from rust/cloud-storage/.sqlx/query-82301526394304e59946caa3c724c377fa46ad214834bc1a876d39ad29ad92ac.json
rename to rust/cloud-storage/.sqlx/query-3fdecaafcd87b6e4776cdc7aeb36e46b5a0410a1229f53886035fd0fd1d88a63.json
index 37446ebe78..e6717d3115 100644
--- a/rust/cloud-storage/.sqlx/query-82301526394304e59946caa3c724c377fa46ad214834bc1a876d39ad29ad92ac.json
+++ b/rust/cloud-storage/.sqlx/query-3fdecaafcd87b6e4776cdc7aeb36e46b5a0410a1229f53886035fd0fd1d88a63.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n t.id,\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n (\n SELECT EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m_imp.thread_id = t.id\n AND l.name = 'IMPORTANT'\n AND l.link_id = t.link_id\n )\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Efficiently find and sort ONLY the top N+1 candidate threads.\n -- This subquery only touches `threads` and `user_history`.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.inbox_visible,\n t.is_read,\n t.project_id,\n t.latest_outbound_message_ts AS created_at,\n t.latest_outbound_message_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_outbound_message_ts)\n ELSE t.latest_outbound_message_ts\n END AS effective_ts\n FROM email_threads t\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n t.link_id = $1\n AND t.latest_outbound_message_ts IS NOT NULL\n \n -- Cursor logic moved inside for maximum efficiency\n AND (($3::timestamptz IS NULL) OR (\n -- This CASE must exactly match the one that defines `effective_ts`\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_outbound_message_ts)\n ELSE t.latest_outbound_message_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find its latest SENT, non-trashed message.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name,\n m.is_draft\n FROM email_messages m\n WHERE m.thread_id = t.id\n AND m.is_sent = TRUE -- This condition is specific to the \"Sent\" view\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = t.link_id\n )\n ORDER BY m.internal_date_ts DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details for the final result set.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n -- Final ordering is preserved because the input `t` is already sorted.\n ORDER BY t.effective_ts DESC, t.updated_at DESC\n ",
+ "query": "\n SELECT\n t.id,\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n (\n SELECT EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m_imp.thread_id = t.id\n AND l.name = 'IMPORTANT'\n AND l.link_id = t.link_id\n )\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Efficiently find and sort ONLY the top N+1 candidate threads.\n -- This subquery only touches `threads` and `user_history`.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.inbox_visible,\n t.is_read,\n t.project_id,\n t.latest_outbound_message_ts AS created_at,\n t.latest_outbound_message_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_outbound_message_ts)\n ELSE t.latest_outbound_message_ts\n END AS effective_ts\n FROM email_threads t\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n t.link_id = ANY($1)\n AND t.latest_outbound_message_ts IS NOT NULL\n \n -- Cursor logic moved inside for maximum efficiency\n AND (($3::timestamptz IS NULL) OR (\n -- This CASE must exactly match the one that defines `effective_ts`\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_outbound_message_ts)\n ELSE t.latest_outbound_message_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find its latest SENT, non-trashed message.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name,\n m.is_draft\n FROM email_messages m\n WHERE m.thread_id = t.id\n AND m.is_sent = TRUE -- This condition is specific to the \"Sent\" view\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = t.link_id\n )\n ORDER BY m.internal_date_ts DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details for the final result set.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n -- Final ordering is preserved because the input `t` is already sorted.\n ORDER BY t.effective_ts DESC, t.updated_at DESC\n ",
"describe": {
"columns": [
{
@@ -91,7 +91,7 @@
],
"parameters": {
"Left": [
- "Uuid",
+ "UuidArray",
"Int8",
"Timestamptz",
"Uuid",
@@ -118,5 +118,5 @@
false
]
},
- "hash": "82301526394304e59946caa3c724c377fa46ad214834bc1a876d39ad29ad92ac"
+ "hash": "3fdecaafcd87b6e4776cdc7aeb36e46b5a0410a1229f53886035fd0fd1d88a63"
}
diff --git a/rust/cloud-storage/.sqlx/query-45930469737986c5b9c3055100e9bc14644eb671d892b299e93fef31f0df9d9e.json b/rust/cloud-storage/.sqlx/query-45930469737986c5b9c3055100e9bc14644eb671d892b299e93fef31f0df9d9e.json
new file mode 100644
index 0000000000..a0b5543e3a
--- /dev/null
+++ b/rust/cloud-storage/.sqlx/query-45930469737986c5b9c3055100e9bc14644eb671d892b299e93fef31f0df9d9e.json
@@ -0,0 +1,122 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH spam_labels AS (\n SELECT id, link_id FROM email_labels WHERE link_id = ANY($1) AND name = 'SPAM'\n ),\n trash_labels AS (\n SELECT id, link_id FROM email_labels WHERE link_id = ANY($1) AND name = 'TRASH'\n ),\n important_labels AS (\n SELECT id, link_id FROM email_labels WHERE link_id = ANY($1) AND name = 'IMPORTANT'\n )\n SELECT\n t.id,\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n JOIN important_labels il ON ml.label_id = il.id\n WHERE m_imp.thread_id = t.id\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Efficiently find, sort, and limit the top N+1 threads.\n -- This subquery only touches `threads` and `user_history`, making it very fast.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.inbox_visible,\n t.is_read,\n t.project_id,\n t.latest_non_spam_message_ts AS created_at,\n t.latest_non_spam_message_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_non_spam_message_ts)\n ELSE t.latest_non_spam_message_ts\n END AS effective_ts\n FROM email_threads t\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n t.link_id = ANY($1)\n AND t.latest_non_spam_message_ts IS NOT NULL\n\n -- Cursor logic is moved inside for maximum efficiency\n AND (($3::timestamptz IS NULL) OR (\n -- This CASE must exactly match the one that defines `effective_ts`\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_non_spam_message_ts)\n ELSE t.latest_non_spam_message_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find its latest non-SPAM/TRASH message.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.is_draft,\n m.from_contact_id,\n m.from_name\n FROM email_messages m\n WHERE m.thread_id = t.id\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n JOIN spam_labels sl ON ml.label_id = sl.id\n WHERE ml.message_id = m.id\n )\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n JOIN trash_labels tl ON ml.label_id = tl.id\n WHERE ml.message_id = m.id\n )\n ORDER BY m.internal_date_ts DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details for the final result set.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n ORDER BY t.effective_ts DESC, t.updated_at DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "provider_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "inbox_visible",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 3,
+ "name": "is_read",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 4,
+ "name": "sort_ts!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "viewed_at?",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "name?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 10,
+ "name": "snippet?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 11,
+ "name": "is_draft",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 12,
+ "name": "is_important!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 13,
+ "name": "sender_email?",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 14,
+ "name": "sender_name?",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 15,
+ "name": "sender_photo_url?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 16,
+ "name": "owner_id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "Int8",
+ "Timestamptz",
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ false,
+ false,
+ null,
+ true,
+ true,
+ true,
+ false,
+ true,
+ true,
+ false,
+ null,
+ false,
+ null,
+ true,
+ false
+ ]
+ },
+ "hash": "45930469737986c5b9c3055100e9bc14644eb671d892b299e93fef31f0df9d9e"
+}
diff --git a/rust/cloud-storage/.sqlx/query-03313f689cbc216503f0372eca83b82f58a55d5c030892b6889eb77e76dbae2e.json b/rust/cloud-storage/.sqlx/query-60710a9df963aaf5edfef7d459aa8be243aa9c5fb36da66fa6c2faa8395209af.json
similarity index 65%
rename from rust/cloud-storage/.sqlx/query-03313f689cbc216503f0372eca83b82f58a55d5c030892b6889eb77e76dbae2e.json
rename to rust/cloud-storage/.sqlx/query-60710a9df963aaf5edfef7d459aa8be243aa9c5fb36da66fa6c2faa8395209af.json
index d852429fbd..09db373d19 100644
--- a/rust/cloud-storage/.sqlx/query-03313f689cbc216503f0372eca83b82f58a55d5c030892b6889eb77e76dbae2e.json
+++ b/rust/cloud-storage/.sqlx/query-60710a9df963aaf5edfef7d459aa8be243aa9c5fb36da66fa6c2faa8395209af.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n t.id,\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n (\n SELECT EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m_imp.thread_id = t.id\n AND l.name = 'IMPORTANT'\n AND l.link_id = t.link_id\n )\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Find the latest starred timestamp for each thread, calculate the\n -- effective sort key, then sort and limit the results.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.inbox_visible,\n t.is_read,\n t.project_id,\n lspt.latest_starred_ts AS created_at,\n lspt.latest_starred_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, lspt.latest_starred_ts)\n ELSE lspt.latest_starred_ts\n END AS effective_ts\n FROM (\n -- This sub-subquery efficiently finds the latest starred timestamp for every thread.\n SELECT m.thread_id, MAX(m.internal_date_ts) as latest_starred_ts\n FROM email_messages m\n WHERE m.link_id = $1 AND m.is_starred = TRUE\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = $1\n )\n GROUP BY m.thread_id\n ) lspt\n JOIN email_threads t ON lspt.thread_id = t.id\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n (($3::timestamptz IS NULL) OR (\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, lspt.latest_starred_ts)\n ELSE lspt.latest_starred_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find the full details of its latest starred message.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name,\n m.is_draft\n FROM email_messages m\n WHERE m.thread_id = t.id\n AND m.is_starred = TRUE\n AND m.is_draft = FALSE\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = t.link_id\n )\n ORDER BY m.internal_date_ts DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n ORDER BY t.effective_ts DESC, t.updated_at DESC\n ",
+ "query": "\n SELECT\n t.id,\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n (\n SELECT EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m_imp.thread_id = t.id\n AND l.name = 'IMPORTANT'\n AND l.link_id = t.link_id\n )\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Find the latest starred timestamp for each thread, calculate the\n -- effective sort key, then sort and limit the results.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.inbox_visible,\n t.is_read,\n t.project_id,\n lspt.latest_starred_ts AS created_at,\n lspt.latest_starred_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, lspt.latest_starred_ts)\n ELSE lspt.latest_starred_ts\n END AS effective_ts\n FROM (\n -- This sub-subquery efficiently finds the latest starred timestamp for every thread.\n SELECT m.thread_id, MAX(m.internal_date_ts) as latest_starred_ts\n FROM email_messages m\n WHERE m.link_id = ANY($1) AND m.is_starred = TRUE\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = m.link_id\n )\n GROUP BY m.thread_id\n ) lspt\n JOIN email_threads t ON lspt.thread_id = t.id\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n (($3::timestamptz IS NULL) OR (\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, lspt.latest_starred_ts)\n ELSE lspt.latest_starred_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find the full details of its latest starred message.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name,\n m.is_draft\n FROM email_messages m\n WHERE m.thread_id = t.id\n AND m.is_starred = TRUE\n AND m.is_draft = FALSE\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = t.link_id\n )\n ORDER BY m.internal_date_ts DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n ORDER BY t.effective_ts DESC, t.updated_at DESC\n ",
"describe": {
"columns": [
{
@@ -91,7 +91,7 @@
],
"parameters": {
"Left": [
- "Uuid",
+ "UuidArray",
"Int8",
"Timestamptz",
"Uuid",
@@ -118,5 +118,5 @@
false
]
},
- "hash": "03313f689cbc216503f0372eca83b82f58a55d5c030892b6889eb77e76dbae2e"
+ "hash": "60710a9df963aaf5edfef7d459aa8be243aa9c5fb36da66fa6c2faa8395209af"
}
diff --git a/rust/cloud-storage/.sqlx/query-8b647d9753ba2b63ba9cc0057e0b71c87592c3e3983205d6969e0b3f1dbdb74b.json b/rust/cloud-storage/.sqlx/query-6e259a736102ed24f06b6f91f7b4a1b47adc45114d3232411f7c391cb88c27b5.json
similarity index 66%
rename from rust/cloud-storage/.sqlx/query-8b647d9753ba2b63ba9cc0057e0b71c87592c3e3983205d6969e0b3f1dbdb74b.json
rename to rust/cloud-storage/.sqlx/query-6e259a736102ed24f06b6f91f7b4a1b47adc45114d3232411f7c391cb88c27b5.json
index 1e10ec0e6e..ec341fdbee 100644
--- a/rust/cloud-storage/.sqlx/query-8b647d9753ba2b63ba9cc0057e0b71c87592c3e3983205d6969e0b3f1dbdb74b.json
+++ b/rust/cloud-storage/.sqlx/query-6e259a736102ed24f06b6f91f7b4a1b47adc45114d3232411f7c391cb88c27b5.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n t.id,\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n (\n SELECT EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m_imp.thread_id = t.id\n AND l.link_id = t.link_id\n AND l.name = 'IMPORTANT'\n )\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Find the latest labeled message timestamp for each thread,\n -- calculate the effective sort key, then sort and limit the results.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.inbox_visible,\n t.is_read,\n t.project_id,\n llpt.latest_labeled_ts AS created_at,\n llpt.latest_labeled_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $6 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, llpt.latest_labeled_ts)\n ELSE llpt.latest_labeled_ts\n END AS effective_ts\n FROM (\n -- This sub-subquery efficiently finds the latest timestamp for every thread\n -- that has at least one message with the specified label.\n SELECT\n m.thread_id,\n MAX(m.internal_date_ts) as latest_labeled_ts\n FROM email_messages m\n JOIN email_message_labels ml ON m.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m.link_id = $1 AND l.name = $5\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml2\n JOIN email_labels l2 ON ml2.label_id = l2.id\n WHERE ml2.message_id = m.id AND l2.name = 'TRASH' AND l2.link_id = $1\n )\n GROUP BY m.thread_id\n ) llpt\n JOIN email_threads t ON llpt.thread_id = t.id\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = $1\n WHERE\n (($3::timestamptz IS NULL) OR (\n CASE $6 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, llpt.latest_labeled_ts)\n ELSE llpt.latest_labeled_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find the full details of its latest message with that specific label.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name,\n m.is_draft\n FROM email_messages m\n JOIN email_message_labels ml ON m.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m.thread_id = t.id AND m.is_draft = FALSE AND l.link_id = t.link_id AND l.name = $5\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml2\n JOIN email_labels l2 ON ml2.label_id = l2.id\n WHERE ml2.message_id = m.id AND l2.name = 'TRASH' AND l2.link_id = t.link_id\n )\n ORDER BY m.internal_date_ts DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n ORDER BY t.effective_ts DESC, t.updated_at DESC\n ",
+ "query": "\n SELECT\n t.id,\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n (\n SELECT EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m_imp.thread_id = t.id\n AND l.link_id = t.link_id\n AND l.name = 'IMPORTANT'\n )\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Find the latest labeled message timestamp for each thread,\n -- calculate the effective sort key, then sort and limit the results.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.inbox_visible,\n t.is_read,\n t.project_id,\n llpt.latest_labeled_ts AS created_at,\n llpt.latest_labeled_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $6 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, llpt.latest_labeled_ts)\n ELSE llpt.latest_labeled_ts\n END AS effective_ts\n FROM (\n -- This sub-subquery efficiently finds the latest timestamp for every thread\n -- that has at least one message with the specified label.\n SELECT\n m.thread_id,\n MAX(m.internal_date_ts) as latest_labeled_ts\n FROM email_messages m\n JOIN email_message_labels ml ON m.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m.link_id = ANY($1) AND l.name = $5\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml2\n JOIN email_labels l2 ON ml2.label_id = l2.id\n WHERE ml2.message_id = m.id AND l2.name = 'TRASH' AND l2.link_id = m.link_id\n )\n GROUP BY m.thread_id\n ) llpt\n JOIN email_threads t ON llpt.thread_id = t.id\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n (($3::timestamptz IS NULL) OR (\n CASE $6 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, llpt.latest_labeled_ts)\n ELSE llpt.latest_labeled_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find the full details of its latest message with that specific label.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name,\n m.is_draft\n FROM email_messages m\n JOIN email_message_labels ml ON m.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m.thread_id = t.id AND m.is_draft = FALSE AND l.link_id = t.link_id AND l.name = $5\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml2\n JOIN email_labels l2 ON ml2.label_id = l2.id\n WHERE ml2.message_id = m.id AND l2.name = 'TRASH' AND l2.link_id = t.link_id\n )\n ORDER BY m.internal_date_ts DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n ORDER BY t.effective_ts DESC, t.updated_at DESC\n ",
"describe": {
"columns": [
{
@@ -91,7 +91,7 @@
],
"parameters": {
"Left": [
- "Uuid",
+ "UuidArray",
"Int8",
"Timestamptz",
"Uuid",
@@ -119,5 +119,5 @@
false
]
},
- "hash": "8b647d9753ba2b63ba9cc0057e0b71c87592c3e3983205d6969e0b3f1dbdb74b"
+ "hash": "6e259a736102ed24f06b6f91f7b4a1b47adc45114d3232411f7c391cb88c27b5"
}
diff --git a/rust/cloud-storage/.sqlx/query-714f90b277b3e53e84688fbe6b573cd622f5c320c33ab43c3c952aa9c12199b3.json b/rust/cloud-storage/.sqlx/query-714f90b277b3e53e84688fbe6b573cd622f5c320c33ab43c3c952aa9c12199b3.json
deleted file mode 100644
index ed19453502..0000000000
--- a/rust/cloud-storage/.sqlx/query-714f90b277b3e53e84688fbe6b573cd622f5c320c33ab43c3c952aa9c12199b3.json
+++ /dev/null
@@ -1,122 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH ApplicableLabelIDs AS (\n SELECT id\n FROM email_labels\n WHERE link_id = $1\n AND (name = 'INBOX')\n ),\n QualifyingMessages AS (\n SELECT m.thread_id,\n m.internal_date_ts,\n m.created_at AS fallback_ts,\n m.is_draft,\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name\n FROM email_messages m\n WHERE m.link_id = $1\n AND NOT EXISTS (\n SELECT 1\n FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id\n AND l.name = 'TRASH'\n AND l.link_id = $1\n )\n AND EXISTS (\n SELECT 1\n FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id\n AND l.name = 'IMPORTANT'\n )\n AND EXISTS (\n SELECT 1\n FROM email_message_labels ml\n JOIN ApplicableLabelIDs ali ON ml.label_id = ali.id\n WHERE ml.message_id = m.id\n )\n\n UNION ALL\n\n SELECT m.thread_id,\n m.internal_date_ts,\n m.created_at AS fallback_ts,\n m.is_draft,\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name\n FROM email_messages m\n WHERE m.link_id = $1\n AND m.is_draft = TRUE\n AND NOT EXISTS (\n SELECT 1\n FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id\n AND l.name = 'TRASH'\n AND l.link_id = $1\n )\n ),\n AllImportantThreads AS (\n -- From all qualifying messages, get the single most recent one per thread.\n SELECT DISTINCT ON (thread_id)\n thread_id,\n internal_date_ts,\n fallback_ts,\n is_draft,\n subject,\n snippet,\n from_contact_id,\n from_name\n FROM QualifyingMessages\n ORDER BY thread_id, COALESCE(internal_date_ts, fallback_ts) DESC\n ),\n ImportantWithSortKey AS (\n -- Join with user_history to calculate the final effective sort key.\n SELECT\n ait.thread_id,\n ait.internal_date_ts,\n ait.fallback_ts,\n ait.is_draft,\n ait.subject,\n ait.snippet,\n ait.from_contact_id,\n ait.from_name,\n COALESCE(ait.internal_date_ts, ait.fallback_ts) as created_at,\n COALESCE(ait.internal_date_ts, ait.fallback_ts) as updated_at,\n uh.updated_at as viewed_at,\n -- This CASE statement dynamically selects the correct timestamp for sorting.\n -- For 'updated_at' and 'created_at', we use the important message timestamp\n -- For 'viewed_at', we use the history timestamp.\n -- For 'viewed_updated', we use the history timestamp if it exists, otherwise the important message timestamp.\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, COALESCE(ait.internal_date_ts, ait.fallback_ts))\n ELSE COALESCE(ait.internal_date_ts, ait.fallback_ts)\n END AS effective_ts\n FROM AllImportantThreads ait\n -- This has to be a left join to support all sort methods.\n LEFT JOIN email_user_history uh ON uh.thread_id = ait.thread_id AND uh.link_id = $1\n )\n SELECT\n isk.thread_id as \"id!\",\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n isk.effective_ts as \"sort_ts!\",\n isk.created_at as \"created_at!\",\n isk.updated_at as \"updated_at!\",\n t.project_id,\n isk.viewed_at as \"viewed_at?\",\n isk.is_draft as \"is_draft!\",\n -- It's the important view - all threads here are important\n true as \"is_important!\",\n isk.subject as \"name?\",\n isk.snippet as \"snippet?\",\n c.email_address AS \"sender_email?\",\n COALESCE(isk.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM ImportantWithSortKey isk\n JOIN email_threads t ON isk.thread_id = t.id\n LEFT JOIN email_contacts c ON isk.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n WHERE\n ($3::timestamptz IS NULL) OR (isk.effective_ts, isk.thread_id) < ($3::timestamptz, $4::uuid)\n ORDER BY isk.effective_ts DESC, isk.thread_id DESC\n LIMIT $2\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id!",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "provider_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "inbox_visible",
- "type_info": "Bool"
- },
- {
- "ordinal": 3,
- "name": "is_read",
- "type_info": "Bool"
- },
- {
- "ordinal": 4,
- "name": "sort_ts!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 5,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 6,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 8,
- "name": "viewed_at?",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "is_draft!",
- "type_info": "Bool"
- },
- {
- "ordinal": 10,
- "name": "is_important!",
- "type_info": "Bool"
- },
- {
- "ordinal": 11,
- "name": "name?",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "snippet?",
- "type_info": "Text"
- },
- {
- "ordinal": 13,
- "name": "sender_email?",
- "type_info": "Varchar"
- },
- {
- "ordinal": 14,
- "name": "sender_name?",
- "type_info": "Varchar"
- },
- {
- "ordinal": 15,
- "name": "sender_photo_url?",
- "type_info": "Text"
- },
- {
- "ordinal": 16,
- "name": "owner_id!",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "Int8",
- "Timestamptz",
- "Uuid",
- "Text"
- ]
- },
- "nullable": [
- null,
- true,
- false,
- false,
- null,
- null,
- null,
- true,
- false,
- null,
- null,
- null,
- null,
- false,
- null,
- true,
- false
- ]
- },
- "hash": "714f90b277b3e53e84688fbe6b573cd622f5c320c33ab43c3c952aa9c12199b3"
-}
diff --git a/rust/cloud-storage/.sqlx/query-8519d142dcd5c9c6b60b9c61c24eca0b0c860eee7227124be31b2fcbff39e2bd.json b/rust/cloud-storage/.sqlx/query-8519d142dcd5c9c6b60b9c61c24eca0b0c860eee7227124be31b2fcbff39e2bd.json
deleted file mode 100644
index 14e048261e..0000000000
--- a/rust/cloud-storage/.sqlx/query-8519d142dcd5c9c6b60b9c61c24eca0b0c860eee7227124be31b2fcbff39e2bd.json
+++ /dev/null
@@ -1,122 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH trash_label AS (\n SELECT id FROM email_labels WHERE link_id = $1 AND name = 'TRASH'\n ),\n important_label AS (\n SELECT id FROM email_labels WHERE link_id = $1 AND name = 'IMPORTANT'\n )\n SELECT\n t.id,\n t.provider_id,\n TRUE AS \"inbox_visible!\",\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n WHERE m_imp.thread_id = t.id\n AND ml.label_id = (SELECT id FROM important_label)\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Efficiently find and sort ONLY the top N+1 candidate threads.\n -- This subquery is fast as it only touches `threads` and `user_history`.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.is_read,\n t.project_id,\n t.latest_inbound_message_ts AS created_at,\n t.latest_inbound_message_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_inbound_message_ts)\n ELSE t.latest_inbound_message_ts\n END AS effective_ts\n FROM email_threads t\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n t.link_id = $1\n AND t.inbox_visible = TRUE\n AND t.latest_inbound_message_ts IS NOT NULL\n \n -- The cursor logic is moved inside this subquery for maximum efficiency.\n AND (($3::timestamptz IS NULL) OR (\n -- This CASE must exactly match the one that defines `effective_ts`\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_inbound_message_ts)\n ELSE t.latest_inbound_message_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC -- fall back to updated_at if effective_ts is the same\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find its latest non-trashed message.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name,\n m.is_draft\n FROM email_messages m\n WHERE m.thread_id = t.id\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n WHERE ml.message_id = m.id\n AND ml.label_id = (SELECT id FROM trash_label)\n )\n ORDER BY m.internal_date_ts DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details for the final result set.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n -- Final ordering is preserved because the input `t` is already sorted.\n ORDER BY t.effective_ts DESC, t.updated_at DESC -- fall back to updated_at if effective_ts is the same\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "provider_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "inbox_visible!",
- "type_info": "Bool"
- },
- {
- "ordinal": 3,
- "name": "is_read",
- "type_info": "Bool"
- },
- {
- "ordinal": 4,
- "name": "sort_ts!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 5,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 6,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 8,
- "name": "viewed_at?",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "name?",
- "type_info": "Text"
- },
- {
- "ordinal": 10,
- "name": "snippet?",
- "type_info": "Text"
- },
- {
- "ordinal": 11,
- "name": "is_draft",
- "type_info": "Bool"
- },
- {
- "ordinal": 12,
- "name": "is_important!",
- "type_info": "Bool"
- },
- {
- "ordinal": 13,
- "name": "sender_email?",
- "type_info": "Varchar"
- },
- {
- "ordinal": 14,
- "name": "sender_name?",
- "type_info": "Varchar"
- },
- {
- "ordinal": 15,
- "name": "sender_photo_url?",
- "type_info": "Text"
- },
- {
- "ordinal": 16,
- "name": "owner_id!",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "Int8",
- "Timestamptz",
- "Uuid",
- "Text"
- ]
- },
- "nullable": [
- false,
- true,
- null,
- false,
- null,
- true,
- true,
- true,
- false,
- true,
- true,
- false,
- null,
- false,
- null,
- true,
- false
- ]
- },
- "hash": "8519d142dcd5c9c6b60b9c61c24eca0b0c860eee7227124be31b2fcbff39e2bd"
-}
diff --git a/rust/cloud-storage/.sqlx/query-a774adbda891d81dd017de5b0b50f41a5a1da6e4c5a81e51eb3cb267f10ef1fc.json b/rust/cloud-storage/.sqlx/query-85d69f162075e61284c5db892a0b771facff06efe446a9b002254447ffcd4a9a.json
similarity index 61%
rename from rust/cloud-storage/.sqlx/query-a774adbda891d81dd017de5b0b50f41a5a1da6e4c5a81e51eb3cb267f10ef1fc.json
rename to rust/cloud-storage/.sqlx/query-85d69f162075e61284c5db892a0b771facff06efe446a9b002254447ffcd4a9a.json
index ca7b895e22..36db6c1cf4 100644
--- a/rust/cloud-storage/.sqlx/query-a774adbda891d81dd017de5b0b50f41a5a1da6e4c5a81e51eb3cb267f10ef1fc.json
+++ b/rust/cloud-storage/.sqlx/query-85d69f162075e61284c5db892a0b771facff06efe446a9b002254447ffcd4a9a.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n t.id,\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n -- A thread in \"Other\" can still be \"Important\", so we must perform the check.\n (\n SELECT EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m_imp.thread_id = t.id\n AND l.link_id = t.link_id\n AND l.name = 'IMPORTANT'\n )\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Efficiently find, sort, and limit the top N+1 threads that qualify for the \"Other\" inbox.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.inbox_visible,\n t.is_read,\n t.project_id,\n t.latest_non_spam_message_ts AS created_at,\n t.latest_non_spam_message_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_non_spam_message_ts)\n ELSE t.latest_non_spam_message_ts\n END AS effective_ts\n FROM email_threads t\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n t.link_id = $1\n AND t.latest_non_spam_message_ts IS NOT NULL\n -- Inclusion Criteria: Must have a category label.\n AND EXISTS (\n SELECT 1 FROM email_messages m JOIN email_message_labels ml ON m.id = ml.message_id JOIN email_labels l ON ml.label_id = l.id\n WHERE m.thread_id = t.id AND l.link_id = t.link_id AND l.name IN ('CATEGORY_PROMOTIONS', 'CATEGORY_SOCIAL', 'CATEGORY_FORUMS')\n )\n -- ****** CORRECTED EXCLUSION CRITERIA ******\n -- This now matches the logic of your original query, which did NOT filter out 'INBOX' or 'IMPORTANT'.\n AND NOT EXISTS (\n SELECT 1 FROM email_messages m JOIN email_message_labels ml ON m.id = ml.message_id JOIN email_labels l ON ml.label_id = l.id\n WHERE m.thread_id = t.id AND l.link_id = t.link_id AND l.name IN ('SPAM', 'TRASH', 'DRAFT')\n )\n \n AND (($3::timestamptz IS NULL) OR (\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_non_spam_message_ts)\n ELSE t.latest_non_spam_message_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find its latest non-spam/trash message for the preview.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.is_draft,\n m.from_contact_id,\n m.from_name\n FROM email_messages m\n WHERE m.thread_id = t.id\n AND m.is_draft = FALSE\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id AND l.link_id = t.link_id AND l.name IN ('SPAM', 'TRASH')\n )\n ORDER BY m.internal_date_ts DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n ORDER BY t.effective_ts DESC, t.updated_at DESC\n ",
+ "query": "\n SELECT\n t.id,\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n -- A thread in \"Other\" can still be \"Important\", so we must perform the check.\n (\n SELECT EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m_imp.thread_id = t.id\n AND l.link_id = t.link_id\n AND l.name = 'IMPORTANT'\n )\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Efficiently find, sort, and limit the top N+1 threads that qualify for the \"Other\" inbox.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.inbox_visible,\n t.is_read,\n t.project_id,\n t.latest_non_spam_message_ts AS created_at,\n t.latest_non_spam_message_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_non_spam_message_ts)\n ELSE t.latest_non_spam_message_ts\n END AS effective_ts\n FROM email_threads t\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n t.link_id = ANY($1)\n AND t.latest_non_spam_message_ts IS NOT NULL\n -- Inclusion Criteria: Must have a category label.\n AND EXISTS (\n SELECT 1 FROM email_messages m JOIN email_message_labels ml ON m.id = ml.message_id JOIN email_labels l ON ml.label_id = l.id\n WHERE m.thread_id = t.id AND l.link_id = t.link_id AND l.name IN ('CATEGORY_PROMOTIONS', 'CATEGORY_SOCIAL', 'CATEGORY_FORUMS')\n )\n -- ****** CORRECTED EXCLUSION CRITERIA ******\n -- This now matches the logic of your original query, which did NOT filter out 'INBOX' or 'IMPORTANT'.\n AND NOT EXISTS (\n SELECT 1 FROM email_messages m JOIN email_message_labels ml ON m.id = ml.message_id JOIN email_labels l ON ml.label_id = l.id\n WHERE m.thread_id = t.id AND l.link_id = t.link_id AND l.name IN ('SPAM', 'TRASH', 'DRAFT')\n )\n \n AND (($3::timestamptz IS NULL) OR (\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_non_spam_message_ts)\n ELSE t.latest_non_spam_message_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find its latest non-spam/trash message for the preview.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.is_draft,\n m.from_contact_id,\n m.from_name\n FROM email_messages m\n WHERE m.thread_id = t.id\n AND m.is_draft = FALSE\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id AND l.link_id = t.link_id AND l.name IN ('SPAM', 'TRASH')\n )\n ORDER BY m.internal_date_ts DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n ORDER BY t.effective_ts DESC, t.updated_at DESC\n ",
"describe": {
"columns": [
{
@@ -91,7 +91,7 @@
],
"parameters": {
"Left": [
- "Uuid",
+ "UuidArray",
"Int8",
"Timestamptz",
"Uuid",
@@ -118,5 +118,5 @@
false
]
},
- "hash": "a774adbda891d81dd017de5b0b50f41a5a1da6e4c5a81e51eb3cb267f10ef1fc"
+ "hash": "85d69f162075e61284c5db892a0b771facff06efe446a9b002254447ffcd4a9a"
}
diff --git a/rust/cloud-storage/.sqlx/query-973d37572060a8cc387f72cf18688270bbb644e96783ac2364a2fee306b4dda6.json b/rust/cloud-storage/.sqlx/query-a22651a2cad9617ad15c9fcd80ff929750755818869e48118cc0f91187049afe.json
similarity index 64%
rename from rust/cloud-storage/.sqlx/query-973d37572060a8cc387f72cf18688270bbb644e96783ac2364a2fee306b4dda6.json
rename to rust/cloud-storage/.sqlx/query-a22651a2cad9617ad15c9fcd80ff929750755818869e48118cc0f91187049afe.json
index 8eef2d5952..59afd3022e 100644
--- a/rust/cloud-storage/.sqlx/query-973d37572060a8cc387f72cf18688270bbb644e96783ac2364a2fee306b4dda6.json
+++ b/rust/cloud-storage/.sqlx/query-a22651a2cad9617ad15c9fcd80ff929750755818869e48118cc0f91187049afe.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT id\n FROM email_labels\n WHERE link_id = $1 AND name = 'TRASH'\n ",
+ "query": "\n SELECT id\n FROM email_labels\n WHERE link_id = ANY($1) AND name = 'TRASH'\n ",
"describe": {
"columns": [
{
@@ -11,12 +11,12 @@
],
"parameters": {
"Left": [
- "Uuid"
+ "UuidArray"
]
},
"nullable": [
false
]
},
- "hash": "973d37572060a8cc387f72cf18688270bbb644e96783ac2364a2fee306b4dda6"
+ "hash": "a22651a2cad9617ad15c9fcd80ff929750755818869e48118cc0f91187049afe"
}
diff --git a/rust/cloud-storage/.sqlx/query-a2c42d1ef0b78555844e0feddc14956117973fadd5565af9a2c48c7d2230e05f.json b/rust/cloud-storage/.sqlx/query-a2c42d1ef0b78555844e0feddc14956117973fadd5565af9a2c48c7d2230e05f.json
deleted file mode 100644
index df027cb4f4..0000000000
--- a/rust/cloud-storage/.sqlx/query-a2c42d1ef0b78555844e0feddc14956117973fadd5565af9a2c48c7d2230e05f.json
+++ /dev/null
@@ -1,122 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH spam_label AS (\n SELECT id FROM email_labels WHERE link_id = $1 AND name = 'SPAM'\n ),\n trash_label AS (\n SELECT id FROM email_labels WHERE link_id = $1 AND name = 'TRASH'\n ),\n important_label AS (\n SELECT id FROM email_labels WHERE link_id = $1 AND name = 'IMPORTANT'\n )\n SELECT\n t.id,\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n WHERE m_imp.thread_id = t.id\n AND ml.label_id = (SELECT id FROM important_label)\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Efficiently find, sort, and limit the top N+1 threads.\n -- This subquery only touches `threads` and `user_history`, making it very fast.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.inbox_visible,\n t.is_read,\n t.project_id,\n t.latest_non_spam_message_ts AS created_at,\n t.latest_non_spam_message_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_non_spam_message_ts)\n ELSE t.latest_non_spam_message_ts\n END AS effective_ts\n FROM email_threads t\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n t.link_id = $1\n AND t.latest_non_spam_message_ts IS NOT NULL\n \n -- Cursor logic is moved inside for maximum efficiency\n AND (($3::timestamptz IS NULL) OR (\n -- This CASE must exactly match the one that defines `effective_ts`\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, t.latest_non_spam_message_ts)\n ELSE t.latest_non_spam_message_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find its latest non-SPAM/TRASH message.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.is_draft,\n m.from_contact_id,\n m.from_name\n FROM email_messages m\n WHERE m.thread_id = t.id\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n WHERE ml.message_id = m.id\n AND ml.label_id = (SELECT id FROM spam_label)\n )\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n WHERE ml.message_id = m.id\n AND ml.label_id = (SELECT id FROM trash_label)\n )\n ORDER BY m.internal_date_ts DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details for the final result set.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n ORDER BY t.effective_ts DESC, t.updated_at DESC\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "provider_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "inbox_visible",
- "type_info": "Bool"
- },
- {
- "ordinal": 3,
- "name": "is_read",
- "type_info": "Bool"
- },
- {
- "ordinal": 4,
- "name": "sort_ts!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 5,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 6,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 8,
- "name": "viewed_at?",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "name?",
- "type_info": "Text"
- },
- {
- "ordinal": 10,
- "name": "snippet?",
- "type_info": "Text"
- },
- {
- "ordinal": 11,
- "name": "is_draft",
- "type_info": "Bool"
- },
- {
- "ordinal": 12,
- "name": "is_important!",
- "type_info": "Bool"
- },
- {
- "ordinal": 13,
- "name": "sender_email?",
- "type_info": "Varchar"
- },
- {
- "ordinal": 14,
- "name": "sender_name?",
- "type_info": "Varchar"
- },
- {
- "ordinal": 15,
- "name": "sender_photo_url?",
- "type_info": "Text"
- },
- {
- "ordinal": 16,
- "name": "owner_id!",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "Int8",
- "Timestamptz",
- "Uuid",
- "Text"
- ]
- },
- "nullable": [
- false,
- true,
- false,
- false,
- null,
- true,
- true,
- true,
- false,
- true,
- true,
- false,
- null,
- false,
- null,
- true,
- false
- ]
- },
- "hash": "a2c42d1ef0b78555844e0feddc14956117973fadd5565af9a2c48c7d2230e05f"
-}
diff --git a/rust/cloud-storage/.sqlx/query-60fe557b143af00c5ddce77735e8b629dcce80126672a6c1d6bb9d2677976c75.json b/rust/cloud-storage/.sqlx/query-a41adc6c58c65f57c24024944c53511df82109d39b5a8aee46bc8759eb07d2a2.json
similarity index 65%
rename from rust/cloud-storage/.sqlx/query-60fe557b143af00c5ddce77735e8b629dcce80126672a6c1d6bb9d2677976c75.json
rename to rust/cloud-storage/.sqlx/query-a41adc6c58c65f57c24024944c53511df82109d39b5a8aee46bc8759eb07d2a2.json
index 68fd6aefaa..8b908e8cfc 100644
--- a/rust/cloud-storage/.sqlx/query-60fe557b143af00c5ddce77735e8b629dcce80126672a6c1d6bb9d2677976c75.json
+++ b/rust/cloud-storage/.sqlx/query-a41adc6c58c65f57c24024944c53511df82109d39b5a8aee46bc8759eb07d2a2.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n t.id,\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n (\n SELECT EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m_imp.thread_id = t.id\n AND l.name = 'IMPORTANT'\n AND l.link_id = t.link_id\n )\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Find the latest draft timestamp for each thread, calculate the\n -- effective sort key, then sort and limit the results. This is the core optimization.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.inbox_visible,\n t.is_read,\n t.project_id,\n ldpt.latest_draft_ts AS created_at,\n ldpt.latest_draft_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, ldpt.latest_draft_ts)\n ELSE ldpt.latest_draft_ts\n END AS effective_ts\n FROM (\n -- This sub-subquery efficiently finds the latest draft timestamp for every thread.\n SELECT m.thread_id, MAX(m.updated_at) as latest_draft_ts\n FROM email_messages m\n -- we only display macro drafts, not drafts created in gmail\n WHERE m.link_id = $1 AND m.is_draft = TRUE AND m.internal_date_ts IS NULL\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = $1\n )\n GROUP BY m.thread_id\n ) ldpt\n JOIN email_threads t ON ldpt.thread_id = t.id\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n (($3::timestamptz IS NULL) OR (\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, ldpt.latest_draft_ts)\n ELSE ldpt.latest_draft_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find the full details of its latest draft.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name,\n m.is_draft\n FROM email_messages m\n WHERE m.thread_id = t.id\n AND m.is_draft = TRUE\n -- we only display macro drafts, not drafts created in gmail\n AND m.internal_date_ts IS NULL\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = t.link_id\n )\n ORDER BY m.updated_at DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n ORDER BY t.effective_ts DESC, t.updated_at DESC\n ",
+ "query": "\n SELECT\n t.id,\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n t.effective_ts AS \"sort_ts!\",\n t.created_at AS \"created_at!\",\n t.updated_at AS \"updated_at!\",\n t.project_id,\n t.viewed_at AS \"viewed_at?\",\n lmp.subject AS \"name?\",\n lmp.snippet AS \"snippet?\",\n lmp.is_draft,\n (\n SELECT EXISTS (\n SELECT 1\n FROM email_messages m_imp\n JOIN email_message_labels ml ON m_imp.id = ml.message_id\n JOIN email_labels l ON ml.label_id = l.id\n WHERE m_imp.thread_id = t.id\n AND l.name = 'IMPORTANT'\n AND l.link_id = t.link_id\n )\n ) AS \"is_important!\",\n c.email_address AS \"sender_email?\",\n COALESCE(lmp.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM (\n -- Step 1: Find the latest draft timestamp for each thread, calculate the\n -- effective sort key, then sort and limit the results. This is the core optimization.\n SELECT\n t.id,\n t.provider_id,\n t.link_id,\n t.inbox_visible,\n t.is_read,\n t.project_id,\n ldpt.latest_draft_ts AS created_at,\n ldpt.latest_draft_ts AS updated_at,\n uh.updated_at AS viewed_at,\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, ldpt.latest_draft_ts)\n ELSE ldpt.latest_draft_ts\n END AS effective_ts\n FROM (\n -- This sub-subquery efficiently finds the latest draft timestamp for every thread.\n SELECT m.thread_id, MAX(m.updated_at) as latest_draft_ts\n FROM email_messages m\n -- we only display macro drafts, not drafts created in gmail\n WHERE m.link_id = ANY($1) AND m.is_draft = TRUE AND m.internal_date_ts IS NULL\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = m.link_id\n )\n GROUP BY m.thread_id\n ) ldpt\n JOIN email_threads t ON ldpt.thread_id = t.id\n LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id\n WHERE\n (($3::timestamptz IS NULL) OR (\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, ldpt.latest_draft_ts)\n ELSE ldpt.latest_draft_ts\n END, t.id\n ) < ($3::timestamptz, $4::uuid))\n ORDER BY effective_ts DESC, t.updated_at DESC\n LIMIT $2\n ) AS t\n -- Step 2: For EACH of the limited threads from above, find the full details of its latest draft.\n CROSS JOIN LATERAL (\n SELECT\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name,\n m.is_draft\n FROM email_messages m\n WHERE m.thread_id = t.id\n AND m.is_draft = TRUE\n -- we only display macro drafts, not drafts created in gmail\n AND m.internal_date_ts IS NULL\n AND NOT EXISTS (\n SELECT 1 FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = t.link_id\n )\n ORDER BY m.updated_at DESC\n LIMIT 1\n ) AS lmp\n -- Step 3: Join to get the sender's details.\n LEFT JOIN email_contacts c ON lmp.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n ORDER BY t.effective_ts DESC, t.updated_at DESC\n ",
"describe": {
"columns": [
{
@@ -91,7 +91,7 @@
],
"parameters": {
"Left": [
- "Uuid",
+ "UuidArray",
"Int8",
"Timestamptz",
"Uuid",
@@ -118,5 +118,5 @@
false
]
},
- "hash": "60fe557b143af00c5ddce77735e8b629dcce80126672a6c1d6bb9d2677976c75"
+ "hash": "a41adc6c58c65f57c24024944c53511df82109d39b5a8aee46bc8759eb07d2a2"
}
diff --git a/rust/cloud-storage/.sqlx/query-d1e1c7c923f73496f7470173e0825641124ea6d4ca0bc37690c43f8d8f5a2661.json b/rust/cloud-storage/.sqlx/query-acd29bfac7388548a2d09bd8a9a12b4c9bb92fe9450fa0950e91bcebfcb1adeb.json
similarity index 73%
rename from rust/cloud-storage/.sqlx/query-d1e1c7c923f73496f7470173e0825641124ea6d4ca0bc37690c43f8d8f5a2661.json
rename to rust/cloud-storage/.sqlx/query-acd29bfac7388548a2d09bd8a9a12b4c9bb92fe9450fa0950e91bcebfcb1adeb.json
index bd2714df55..06b0392082 100644
--- a/rust/cloud-storage/.sqlx/query-d1e1c7c923f73496f7470173e0825641124ea6d4ca0bc37690c43f8d8f5a2661.json
+++ b/rust/cloud-storage/.sqlx/query-acd29bfac7388548a2d09bd8a9a12b4c9bb92fe9450fa0950e91bcebfcb1adeb.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT id, LOWER(email_address) AS \"email_lower!\"\n FROM email_contacts\n WHERE link_id = $1 AND LOWER(email_address) = ANY($2)\n ",
+ "query": "\n SELECT id, LOWER(email_address) AS \"email_lower!\"\n FROM email_contacts\n WHERE link_id = ANY($1) AND LOWER(email_address) = ANY($2)\n ",
"describe": {
"columns": [
{
@@ -16,7 +16,7 @@
],
"parameters": {
"Left": [
- "Uuid",
+ "UuidArray",
"TextArray"
]
},
@@ -25,5 +25,5 @@
null
]
},
- "hash": "d1e1c7c923f73496f7470173e0825641124ea6d4ca0bc37690c43f8d8f5a2661"
+ "hash": "acd29bfac7388548a2d09bd8a9a12b4c9bb92fe9450fa0950e91bcebfcb1adeb"
}
diff --git a/rust/cloud-storage/.sqlx/query-fe76f71ae6e0484ff8d47427ccc0eecee1c64c422b0745a6ba5d0cd680e56f9e.json b/rust/cloud-storage/.sqlx/query-fe76f71ae6e0484ff8d47427ccc0eecee1c64c422b0745a6ba5d0cd680e56f9e.json
new file mode 100644
index 0000000000..9bc626ab26
--- /dev/null
+++ b/rust/cloud-storage/.sqlx/query-fe76f71ae6e0484ff8d47427ccc0eecee1c64c422b0745a6ba5d0cd680e56f9e.json
@@ -0,0 +1,122 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH ApplicableLabelIDs AS (\n SELECT id\n FROM email_labels\n WHERE link_id = ANY($1)\n AND (name = 'INBOX')\n ),\n QualifyingMessages AS (\n SELECT m.thread_id,\n m.internal_date_ts,\n m.created_at AS fallback_ts,\n m.is_draft,\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name\n FROM email_messages m\n WHERE m.link_id = ANY($1)\n AND NOT EXISTS (\n SELECT 1\n FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id\n AND l.name = 'TRASH'\n AND l.link_id = m.link_id\n )\n AND EXISTS (\n SELECT 1\n FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id\n AND l.name = 'IMPORTANT'\n )\n AND EXISTS (\n SELECT 1\n FROM email_message_labels ml\n JOIN ApplicableLabelIDs ali ON ml.label_id = ali.id\n WHERE ml.message_id = m.id\n )\n\n UNION ALL\n\n SELECT m.thread_id,\n m.internal_date_ts,\n m.created_at AS fallback_ts,\n m.is_draft,\n m.subject,\n m.snippet,\n m.from_contact_id,\n m.from_name\n FROM email_messages m\n WHERE m.link_id = ANY($1)\n AND m.is_draft = TRUE\n AND NOT EXISTS (\n SELECT 1\n FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = m.id\n AND l.name = 'TRASH'\n AND l.link_id = m.link_id\n )\n ),\n AllImportantThreads AS (\n -- From all qualifying messages, get the single most recent one per thread.\n SELECT DISTINCT ON (thread_id)\n thread_id,\n internal_date_ts,\n fallback_ts,\n is_draft,\n subject,\n snippet,\n from_contact_id,\n from_name\n FROM QualifyingMessages\n ORDER BY thread_id, COALESCE(internal_date_ts, fallback_ts) DESC\n ),\n ImportantWithSortKey AS (\n -- Join with user_history to calculate the final effective sort key.\n SELECT\n ait.thread_id,\n ait.internal_date_ts,\n ait.fallback_ts,\n ait.is_draft,\n ait.subject,\n ait.snippet,\n ait.from_contact_id,\n ait.from_name,\n COALESCE(ait.internal_date_ts, ait.fallback_ts) as created_at,\n COALESCE(ait.internal_date_ts, ait.fallback_ts) as updated_at,\n uh.updated_at as viewed_at,\n -- This CASE statement dynamically selects the correct timestamp for sorting.\n -- For 'updated_at' and 'created_at', we use the important message timestamp\n -- For 'viewed_at', we use the history timestamp.\n -- For 'viewed_updated', we use the history timestamp if it exists, otherwise the important message timestamp.\n CASE $5 -- sort_method_str\n WHEN 'viewed_at' THEN COALESCE(uh.\"updated_at\", '1970-01-01 00:00:00+00')\n WHEN 'viewed_updated' THEN COALESCE(uh.updated_at, COALESCE(ait.internal_date_ts, ait.fallback_ts))\n ELSE COALESCE(ait.internal_date_ts, ait.fallback_ts)\n END AS effective_ts\n FROM AllImportantThreads ait\n JOIN email_threads tt ON tt.id = ait.thread_id\n -- This has to be a left join to support all sort methods.\n LEFT JOIN email_user_history uh ON uh.thread_id = ait.thread_id AND uh.link_id = tt.link_id\n )\n SELECT\n isk.thread_id as \"id!\",\n t.provider_id,\n t.inbox_visible,\n t.is_read,\n isk.effective_ts as \"sort_ts!\",\n isk.created_at as \"created_at!\",\n isk.updated_at as \"updated_at!\",\n t.project_id,\n isk.viewed_at as \"viewed_at?\",\n isk.is_draft as \"is_draft!\",\n -- It's the important view - all threads here are important\n true as \"is_important!\",\n isk.subject as \"name?\",\n isk.snippet as \"snippet?\",\n c.email_address AS \"sender_email?\",\n COALESCE(isk.from_name, c.name) AS \"sender_name?\",\n c.sfs_photo_url as \"sender_photo_url?\",\n el.macro_id AS \"owner_id!\"\n FROM ImportantWithSortKey isk\n JOIN email_threads t ON isk.thread_id = t.id\n LEFT JOIN email_contacts c ON isk.from_contact_id = c.id\n JOIN email_links el ON t.link_id = el.id\n WHERE\n ($3::timestamptz IS NULL) OR (isk.effective_ts, isk.thread_id) < ($3::timestamptz, $4::uuid)\n ORDER BY isk.effective_ts DESC, isk.thread_id DESC\n LIMIT $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "provider_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "inbox_visible",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 3,
+ "name": "is_read",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 4,
+ "name": "sort_ts!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "viewed_at?",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "is_draft!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 10,
+ "name": "is_important!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 11,
+ "name": "name?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "snippet?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 13,
+ "name": "sender_email?",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 14,
+ "name": "sender_name?",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 15,
+ "name": "sender_photo_url?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 16,
+ "name": "owner_id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "Int8",
+ "Timestamptz",
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ true,
+ false,
+ false,
+ null,
+ null,
+ null,
+ true,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ null,
+ true,
+ false
+ ]
+ },
+ "hash": "fe76f71ae6e0484ff8d47427ccc0eecee1c64c422b0745a6ba5d0cd680e56f9e"
+}
diff --git a/rust/cloud-storage/email/src/domain/models/preview.rs b/rust/cloud-storage/email/src/domain/models/preview.rs
index 21a2a79c7d..5b55695aeb 100644
--- a/rust/cloud-storage/email/src/domain/models/preview.rs
+++ b/rust/cloud-storage/email/src/domain/models/preview.rs
@@ -16,12 +16,12 @@ use super::label::Label;
#[derive(Debug)]
pub struct PreviewCursorQuery {
pub view: PreviewView,
- pub link_id: Uuid,
+ pub link_ids: Vec<Uuid>,
pub limit: u32,
pub query: Query<Uuid, SimpleSortMethod, LiteralTree<EmailLiteral>>,
/// When `Some(team_id)`, the dynamic query path expands the candidate
- /// thread set from "only this `link_id`" to "every `link_id` owned by
- /// any user on this team." Populated by the service after a successful
+ /// thread set from "only `link_ids`" to "every `link_id` owned by any
+ /// user on this team." Populated by the service after a successful
/// CRM-scope validation (see `validate_crm_scope`).
pub team_id: Option<Uuid>,
}
@@ -137,7 +137,10 @@ impl SortOn<SimpleSortMethod> for EnrichedEmailThreadPreview {
pub struct GetEmailsRequest {
pub view: PreviewView,
- pub link_id: Uuid,
+ /// Every inbox the caller can read for this request. Multi-element when
+ /// the caller has linked secondary inboxes or has been delegated access
+ /// via macro_user_links.
+ pub link_ids: Vec<Uuid>,
pub macro_id: MacroUserIdStr<'static>,
pub limit: Option<u32>,
pub query: Query<Uuid, SimpleSortMethod, LiteralTree<EmailLiteral>>,
diff --git a/rust/cloud-storage/email/src/domain/ports.rs b/rust/cloud-storage/email/src/domain/ports.rs
index 696c92e841..6fa762cfac 100644
--- a/rust/cloud-storage/email/src/domain/ports.rs
+++ b/rust/cloud-storage/email/src/domain/ports.rs
@@ -74,6 +74,13 @@ pub trait EmailRepo: Send + Sync + 'static {
macro_id: MacroUserIdStr<'_>,
) -> impl Future<Output = Result<Option<Link>, Self::Err>> + Send;
+ /// Returns every inbox accessible to `macro_id`: their own email_links plus
+ /// any reachable via a `macro_user_links` edge (narrow-graph multi-inbox).
+ fn inboxes_for_macro_id(
+ &self,
+ macro_id: MacroUserIdStr<'_>,
+ ) -> impl Future<Output = Result<Vec<Link>, Self::Err>> + Send;
+
/// Fetch a thread by its database ID (without messages).
fn thread_by_id(
&self,
@@ -315,6 +322,13 @@ pub trait EmailService: Send + Sync + 'static {
macro_id: MacroUserIdStr<'_>,
) -> impl Future<Output = Result<Option<Link>, EmailErr>> + Send;
+ /// Fetch every inbox the caller can read — their own email_links rows plus
+ /// any rows reachable via a `macro_user_links` edge (narrow-graph multi-inbox).
+ fn get_inboxes_for_macro_id(
+ &self,
+ macro_id: MacroUserIdStr<'_>,
+ ) -> impl Future<Output = Result<Vec<Link>, EmailErr>> + Send;
+
/// Fetch a thread with paginated messages, verifying access via the provided receipt.
fn get_thread_with_messages(
&self,
diff --git a/rust/cloud-storage/email/src/domain/service/mod.rs b/rust/cloud-storage/email/src/domain/service/mod.rs
index becc6a2dd8..fd1f6a6b34 100644
--- a/rust/cloud-storage/email/src/domain/service/mod.rs
+++ b/rust/cloud-storage/email/src/domain/service/mod.rs
@@ -149,6 +149,16 @@ where
.map_err(|e| EmailErr::RepoErr(e.into()))
}
+ async fn get_inboxes_for_macro_id(
+ &self,
+ macro_id: macro_user_id::user_id::MacroUserIdStr<'_>,
+ ) -> Result<Vec<crate::domain::models::Link>, EmailErr> {
+ self.email_repo
+ .inboxes_for_macro_id(macro_id)
+ .await
+ .map_err(|e| EmailErr::RepoErr(e.into()))
+ }
+
async fn get_thread_with_messages(
&self,
receipt: EntityAccessReceipt<ViewAccessLevel>,
diff --git a/rust/cloud-storage/email/src/domain/service/previews.rs b/rust/cloud-storage/email/src/domain/service/previews.rs
index accb947354..b3533b92e4 100644
--- a/rust/cloud-storage/email/src/domain/service/previews.rs
+++ b/rust/cloud-storage/email/src/domain/service/previews.rs
@@ -35,7 +35,7 @@ where
{
let GetEmailsRequest {
view,
- link_id,
+ link_ids,
macro_id,
limit,
query,
@@ -56,7 +56,7 @@ where
let query = PreviewCursorQuery {
view,
- link_id,
+ link_ids,
limit,
query,
team_id,
diff --git a/rust/cloud-storage/email/src/inbound/axum/previews_router.rs b/rust/cloud-storage/email/src/inbound/axum/previews_router.rs
index 831d5a0903..9a6154a1ae 100644
--- a/rust/cloud-storage/email/src/inbound/axum/previews_router.rs
+++ b/rust/cloud-storage/email/src/inbound/axum/previews_router.rs
@@ -93,7 +93,7 @@ async fn cursor_handler<T: EmailService>(
.inner
.get_email_thread_previews(GetEmailsRequest {
view: preview_view,
- link_id: link.id,
+ link_ids: vec![link.id],
macro_id: macro_user.macro_user_id,
limit: params.limit,
query: cursor
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/filters.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/filters.rs
index deb8122a94..db517b2f6b 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/filters.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/filters.rs
@@ -30,6 +30,7 @@ pub(super) fn has_thread_literals(ast: &Expr<EmailLiteral>) -> bool {
filter_ast::ExprFrame::Not(a) => a,
filter_ast::ExprFrame::Literal(
EmailLiteral::ThreadId(_)
+ | EmailLiteral::Owner(_)
| EmailLiteral::ProjectId(_)
| EmailLiteral::CalendarOnly(_)
| EmailLiteral::CreatedAt(_)
@@ -46,6 +47,7 @@ pub(super) fn has_message_literals(ast: &Expr<EmailLiteral>) -> bool {
filter_ast::ExprFrame::Not(a) => a,
filter_ast::ExprFrame::Literal(
EmailLiteral::ThreadId(_)
+ | EmailLiteral::Owner(_)
| EmailLiteral::ProjectId(_)
| EmailLiteral::Shared(_)
| EmailLiteral::CalendarOnly(_)
@@ -217,7 +219,9 @@ pub(super) fn build_message_email_filter(
filter_ast::ExprFrame::Not(a) => SqlFragment::not(a),
filter_ast::ExprFrame::Literal(
- EmailLiteral::ThreadId(_) | EmailLiteral::ProjectId(_),
+ EmailLiteral::ThreadId(_)
+ | EmailLiteral::Owner(_)
+ | EmailLiteral::ProjectId(_),
) => SqlFragment::raw("TRUE"),
filter_ast::ExprFrame::Literal(EmailLiteral::Sender(email)) => {
@@ -662,6 +666,12 @@ pub(super) fn build_thread_email_filter(
f
}
+ filter_ast::ExprFrame::Literal(EmailLiteral::Owner(id)) => {
+ let mut f = SqlFragment::raw("t.link_id = ");
+ f.extend(SqlFragment::bind_uuid(id));
+ f
+ }
+
filter_ast::ExprFrame::Literal(EmailLiteral::ProjectId(id)) => {
let mut f = SqlFragment::raw("t.project_id = ");
f.extend(SqlFragment::bind_string(id));
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/query.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/query.rs
index 04ad2d9ee1..5d3f75afc0 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/query.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/query.rs
@@ -13,7 +13,7 @@ use std::sync::Arc;
use uuid::Uuid;
struct QueryParams {
- link_id: Uuid,
+ link_ids: Vec<Uuid>,
sort_method_str: String,
query_limit: i64,
cursor_timestamp: Option<DateTime<Utc>>,
@@ -23,8 +23,8 @@ struct QueryParams {
user_id: String,
resolved: ResolvedFilters,
/// When `Some(team_id)`, the "Owned" candidate source expands from
- /// `t.link_id = $link_id` to `t.link_id IN (links of every member of
- /// $team_id)`. Set only after CRM scope has been validated upstream.
+ /// `t.link_id = ANY($link_ids)` to `t.link_id IN (links of every member
+ /// of $team_id)`. Set only after CRM scope has been validated upstream.
team_id: Option<Uuid>,
}
@@ -117,8 +117,9 @@ fn push_thread_candidate_select(
ThreadCandidateSource::Owned => match params.team_id {
// Normal per-mailbox query.
None => {
- builder.push("t.link_id = ");
- builder.push_bind(params.link_id);
+ builder.push("t.link_id = ANY(");
+ builder.push_bind(params.link_ids.clone());
+ builder.push(")");
}
// CRM-scoped query: expand to every email_link owned by any
// member of the team. The receipt has already been validated
@@ -401,7 +402,7 @@ pub(super) fn debug_build_query_sql_with_resolved(
view,
email_filter,
QueryParams {
- link_id: Uuid::nil(),
+ link_ids: vec![Uuid::nil()],
sort_method_str: SimpleSortMethod::UpdatedAt.to_string(),
query_limit: 50,
cursor_timestamp: None,
@@ -460,7 +461,7 @@ fn extract_shared_filter(ast: &Expr<EmailLiteral>) -> SharedEmailFilter {
#[tracing::instrument(skip(pool), err)]
pub(crate) async fn dynamic_email_thread_cursor(
pool: &PgPool,
- link_id: &Uuid,
+ link_ids: &[Uuid],
limit: u32,
view: &PreviewView,
query: Query<Uuid, SimpleSortMethod, Arc<Expr<EmailLiteral>>>,
@@ -487,7 +488,7 @@ pub(crate) async fn dynamic_email_thread_cursor(
//
// When team_id is set, resolution spans every team-member's link so the
// resulting contact_id / TRASH label_id sets cover all team mailboxes.
- let resolved = resolve_filters(pool, *link_id, team_id, email_filter).await?;
+ let resolved = resolve_filters(pool, link_ids, team_id, email_filter).await?;
if can_short_circuit(email_filter, &resolved) {
return Ok(Vec::new());
}
@@ -496,7 +497,7 @@ pub(crate) async fn dynamic_email_thread_cursor(
view,
email_filter,
QueryParams {
- link_id: *link_id,
+ link_ids: link_ids.to_vec(),
sort_method_str,
query_limit,
cursor_timestamp: cursor_timestamp.copied(),
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/resolve.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/resolve.rs
index 8ee9ebb457..12207b6860 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/resolve.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/resolve.rs
@@ -174,7 +174,7 @@ pub(super) fn can_short_circuit(ast: &Expr<EmailLiteral>, resolved: &ResolvedFil
#[tracing::instrument(skip(pool, ast), err)]
pub(super) async fn resolve_filters(
pool: &PgPool,
- link_id: Uuid,
+ link_ids: &[Uuid],
team_id: Option<Uuid>,
ast: &Expr<EmailLiteral>,
) -> Result<ResolvedFilters, sqlx::Error> {
@@ -184,9 +184,9 @@ pub(super) async fn resolve_filters(
r#"
SELECT id
FROM email_labels
- WHERE link_id = $1 AND name = 'TRASH'
+ WHERE link_id = ANY($1) AND name = 'TRASH'
"#,
- link_id,
+ link_ids,
)
.fetch_all(pool)
.await?
@@ -218,9 +218,9 @@ pub(super) async fn resolve_filters(
r#"
SELECT id, LOWER(email_address) AS "email_lower!"
FROM email_contacts
- WHERE link_id = $1 AND LOWER(email_address) = ANY($2)
+ WHERE link_id = ANY($1) AND LOWER(email_address) = ANY($2)
"#,
- link_id,
+ link_ids,
&emails,
)
.fetch_all(pool)
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/link.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/link.rs
index b7be91938e..b1361969e8 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/link.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/link.rs
@@ -94,3 +94,46 @@ pub(super) async fn link_by_macro_id(
.transpose()
.map_err(|e| sqlx::Error::Decode(Box::new(e)))
}
+
+#[tracing::instrument(err, skip(pool))]
+pub(super) async fn inboxes_for_macro_id(
+ pool: &PgPool,
+ macro_id: MacroUserIdStr<'_>,
+) -> Result<Vec<Link>, sqlx::Error> {
+ let db_links: Vec<DbLink> = sqlx::query_as!(
+ DbLink,
+ r#"
+ SELECT id as "id!", macro_id as "macro_id!",
+ fusionauth_user_id as "fusionauth_user_id!",
+ email_address as "email_address!",
+ provider as "provider!: _",
+ is_sync_active as "is_sync_active!",
+ created_at as "created_at!",
+ updated_at as "updated_at!"
+ FROM (
+ SELECT el.id, el.macro_id, el.fusionauth_user_id, el.email_address,
+ el.provider, el.is_sync_active, el.created_at, el.updated_at
+ FROM email_links el
+ WHERE el.macro_id = $1
+ UNION
+ SELECT el.id, el.macro_id, el.fusionauth_user_id, el.email_address,
+ el.provider, el.is_sync_active, el.created_at, el.updated_at
+ FROM email_links el
+ JOIN macro_user_links mul ON el.macro_id = mul.child_macro_id
+ WHERE mul.primary_macro_id = $1
+ ) AS combined
+ ORDER BY created_at DESC
+ "#,
+ macro_id.as_ref()
+ )
+ .fetch_all(pool)
+ .await?;
+
+ db_links
+ .into_iter()
+ .map(|v| {
+ v.try_into_model()
+ .map_err(|e| sqlx::Error::Decode(Box::new(e)))
+ })
+ .collect()
+}
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/mod.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/mod.rs
index a56ca0aec0..257217dfb5 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/mod.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/mod.rs
@@ -97,6 +97,13 @@ impl EmailRepo for EmailPgRepo {
link::link_by_macro_id(&self.pool, macro_id).await
}
+ async fn inboxes_for_macro_id(
+ &self,
+ macro_id: MacroUserIdStr<'_>,
+ ) -> Result<Vec<Link>, Self::Err> {
+ link::inboxes_for_macro_id(&self.pool, macro_id).await
+ }
+
async fn thread_by_id(&self, thread_id: Uuid) -> Result<Option<ThreadRow>, Self::Err> {
thread::thread_by_id(&self.pool, thread_id).await
}
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview.rs
index 12a7132a7b..440a9732c2 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview.rs
@@ -10,7 +10,7 @@ use uuid::Uuid;
use super::db_types::{AttachmentDbRow, LabelDbRow, ThreadPreviewCursorDbRow};
-#[tracing::instrument(err, skip(pool, query), fields(link_id = %query.link_id, view = %query.view))]
+#[tracing::instrument(err, skip(pool, query), fields(link_count = query.link_ids.len(), view = %query.view))]
pub(super) async fn previews_for_view_cursor(
pool: &PgPool,
query: PreviewCursorQuery,
@@ -18,7 +18,7 @@ pub(super) async fn previews_for_view_cursor(
) -> Result<Vec<EmailThreadPreview>, sqlx::Error> {
let PreviewCursorQuery {
view,
- link_id,
+ link_ids,
limit,
query,
team_id,
@@ -30,7 +30,7 @@ pub(super) async fn previews_for_view_cursor(
(view, Either::Right(dynamic_query)) => {
super::dynamic::dynamic_email_thread_cursor(
pool,
- &link_id,
+ &link_ids,
limit,
&view,
dynamic_query,
@@ -40,38 +40,42 @@ pub(super) async fn previews_for_view_cursor(
.await?
}
(PreviewView::StandardLabel(PreviewViewStandardLabel::Inbox), Either::Left(query)) => {
- super::preview_views::new_inbox::new_inbox_preview_cursor(pool, &link_id, limit, &query)
- .await?
+ super::preview_views::new_inbox::new_inbox_preview_cursor(
+ pool, &link_ids, limit, &query,
+ )
+ .await?
}
(PreviewView::StandardLabel(PreviewViewStandardLabel::Sent), Either::Left(query)) => {
- super::preview_views::sent::sent_preview_cursor(pool, &link_id, limit, &query).await?
+ super::preview_views::sent::sent_preview_cursor(pool, &link_ids, limit, &query).await?
}
(PreviewView::StandardLabel(PreviewViewStandardLabel::Drafts), Either::Left(query)) => {
- super::preview_views::draft::drafts_preview_cursor(pool, &link_id, limit, &query)
+ super::preview_views::draft::drafts_preview_cursor(pool, &link_ids, limit, &query)
.await?
}
(PreviewView::StandardLabel(PreviewViewStandardLabel::Starred), Either::Left(query)) => {
- super::preview_views::starred::starred_preview_cursor(pool, &link_id, limit, &query)
+ super::preview_views::starred::starred_preview_cursor(pool, &link_ids, limit, &query)
.await?
}
(PreviewView::StandardLabel(PreviewViewStandardLabel::All), Either::Left(query)) => {
- super::preview_views::all_mail::all_mail_preview_cursor(pool, &link_id, limit, &query)
+ super::preview_views::all_mail::all_mail_preview_cursor(pool, &link_ids, limit, &query)
.await?
}
(PreviewView::StandardLabel(PreviewViewStandardLabel::Important), Either::Left(query)) => {
- super::preview_views::important::important_preview_cursor(pool, &link_id, limit, &query)
- .await?
+ super::preview_views::important::important_preview_cursor(
+ pool, &link_ids, limit, &query,
+ )
+ .await?
}
(PreviewView::StandardLabel(PreviewViewStandardLabel::Other), Either::Left(query)) => {
super::preview_views::other_inbox::other_inbox_preview_cursor(
- pool, &link_id, limit, &query,
+ pool, &link_ids, limit, &query,
)
.await?
}
(PreviewView::UserLabel(label_name), Either::Left(query)) => {
super::preview_views::user_label::user_label_preview_cursor(
pool,
- &link_id,
+ &link_ids,
limit,
&query,
&label_name,
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/all_mail.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/all_mail.rs
index b43709321a..2c02fdc78a 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/all_mail.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/all_mail.rs
@@ -11,7 +11,7 @@ use uuid::Uuid;
#[tracing::instrument(skip(pool), err)]
pub(crate) async fn all_mail_preview_cursor(
pool: &PgPool,
- link_id: &Uuid,
+ link_ids: &[Uuid],
limit: u32,
query: &Query<Uuid, SimpleSortMethod, ()>,
) -> Result<Vec<ThreadPreviewCursorDbRow>, sqlx::Error> {
@@ -22,14 +22,14 @@ pub(crate) async fn all_mail_preview_cursor(
sqlx::query_as!(
ThreadPreviewCursorDbRow,
r#"
- WITH spam_label AS (
- SELECT id FROM email_labels WHERE link_id = $1 AND name = 'SPAM'
+ WITH spam_labels AS (
+ SELECT id, link_id FROM email_labels WHERE link_id = ANY($1) AND name = 'SPAM'
),
- trash_label AS (
- SELECT id FROM email_labels WHERE link_id = $1 AND name = 'TRASH'
+ trash_labels AS (
+ SELECT id, link_id FROM email_labels WHERE link_id = ANY($1) AND name = 'TRASH'
),
- important_label AS (
- SELECT id FROM email_labels WHERE link_id = $1 AND name = 'IMPORTANT'
+ important_labels AS (
+ SELECT id, link_id FROM email_labels WHERE link_id = ANY($1) AND name = 'IMPORTANT'
)
SELECT
t.id,
@@ -48,8 +48,8 @@ pub(crate) async fn all_mail_preview_cursor(
SELECT 1
FROM email_messages m_imp
JOIN email_message_labels ml ON m_imp.id = ml.message_id
+ JOIN important_labels il ON ml.label_id = il.id
WHERE m_imp.thread_id = t.id
- AND ml.label_id = (SELECT id FROM important_label)
) AS "is_important!",
c.email_address AS "sender_email?",
COALESCE(lmp.from_name, c.name) AS "sender_name?",
@@ -76,9 +76,9 @@ pub(crate) async fn all_mail_preview_cursor(
FROM email_threads t
LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id
WHERE
- t.link_id = $1
+ t.link_id = ANY($1)
AND t.latest_non_spam_message_ts IS NOT NULL
-
+
-- Cursor logic is moved inside for maximum efficiency
AND (($3::timestamptz IS NULL) OR (
-- This CASE must exactly match the one that defines `effective_ts`
@@ -103,13 +103,13 @@ pub(crate) async fn all_mail_preview_cursor(
WHERE m.thread_id = t.id
AND NOT EXISTS (
SELECT 1 FROM email_message_labels ml
+ JOIN spam_labels sl ON ml.label_id = sl.id
WHERE ml.message_id = m.id
- AND ml.label_id = (SELECT id FROM spam_label)
)
AND NOT EXISTS (
SELECT 1 FROM email_message_labels ml
+ JOIN trash_labels tl ON ml.label_id = tl.id
WHERE ml.message_id = m.id
- AND ml.label_id = (SELECT id FROM trash_label)
)
ORDER BY m.internal_date_ts DESC
LIMIT 1
@@ -119,7 +119,7 @@ pub(crate) async fn all_mail_preview_cursor(
JOIN email_links el ON t.link_id = el.id
ORDER BY t.effective_ts DESC, t.updated_at DESC
"#,
- link_id, // $1
+ link_ids, // $1
query_limit, // $2
cursor_timestamp, // $3
cursor_id, // $4
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/draft.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/draft.rs
index 971f715ef1..cc73168b3d 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/draft.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/draft.rs
@@ -9,7 +9,7 @@ use uuid::Uuid;
#[tracing::instrument(skip(pool), err)]
pub(crate) async fn drafts_preview_cursor(
pool: &PgPool,
- link_id: &Uuid,
+ link_ids: &[Uuid],
limit: u32,
query: &Query<Uuid, SimpleSortMethod, ()>,
) -> Result<Vec<ThreadPreviewCursorDbRow>, sqlx::Error> {
@@ -71,11 +71,11 @@ pub(crate) async fn drafts_preview_cursor(
SELECT m.thread_id, MAX(m.updated_at) as latest_draft_ts
FROM email_messages m
-- we only display macro drafts, not drafts created in gmail
- WHERE m.link_id = $1 AND m.is_draft = TRUE AND m.internal_date_ts IS NULL
+ WHERE m.link_id = ANY($1) AND m.is_draft = TRUE AND m.internal_date_ts IS NULL
AND NOT EXISTS (
SELECT 1 FROM email_message_labels ml
JOIN email_labels l ON ml.label_id = l.id
- WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = $1
+ WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = m.link_id
)
GROUP BY m.thread_id
) ldpt
@@ -118,7 +118,7 @@ pub(crate) async fn drafts_preview_cursor(
JOIN email_links el ON t.link_id = el.id
ORDER BY t.effective_ts DESC, t.updated_at DESC
"#,
- link_id, // $1
+ link_ids, // $1
query_limit, // $2
cursor_timestamp, // $3
cursor_id, // $4
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/important.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/important.rs
index 657825ad43..db79fe496a 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/important.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/important.rs
@@ -11,7 +11,7 @@ use uuid::Uuid;
#[tracing::instrument(skip(pool), err)]
pub(crate) async fn important_preview_cursor(
pool: &PgPool,
- link_id: &Uuid,
+ link_ids: &[Uuid],
limit: u32,
query: &Query<Uuid, SimpleSortMethod, ()>,
) -> Result<Vec<ThreadPreviewCursorDbRow>, sqlx::Error> {
@@ -25,7 +25,7 @@ pub(crate) async fn important_preview_cursor(
WITH ApplicableLabelIDs AS (
SELECT id
FROM email_labels
- WHERE link_id = $1
+ WHERE link_id = ANY($1)
AND (name = 'INBOX')
),
QualifyingMessages AS (
@@ -38,14 +38,14 @@ pub(crate) async fn important_preview_cursor(
m.from_contact_id,
m.from_name
FROM email_messages m
- WHERE m.link_id = $1
+ WHERE m.link_id = ANY($1)
AND NOT EXISTS (
SELECT 1
FROM email_message_labels ml
JOIN email_labels l ON ml.label_id = l.id
WHERE ml.message_id = m.id
AND l.name = 'TRASH'
- AND l.link_id = $1
+ AND l.link_id = m.link_id
)
AND EXISTS (
SELECT 1
@@ -72,7 +72,7 @@ pub(crate) async fn important_preview_cursor(
m.from_contact_id,
m.from_name
FROM email_messages m
- WHERE m.link_id = $1
+ WHERE m.link_id = ANY($1)
AND m.is_draft = TRUE
AND NOT EXISTS (
SELECT 1
@@ -80,7 +80,7 @@ pub(crate) async fn important_preview_cursor(
JOIN email_labels l ON ml.label_id = l.id
WHERE ml.message_id = m.id
AND l.name = 'TRASH'
- AND l.link_id = $1
+ AND l.link_id = m.link_id
)
),
AllImportantThreads AS (
@@ -121,8 +121,9 @@ pub(crate) async fn important_preview_cursor(
ELSE COALESCE(ait.internal_date_ts, ait.fallback_ts)
END AS effective_ts
FROM AllImportantThreads ait
+ JOIN email_threads tt ON tt.id = ait.thread_id
-- This has to be a left join to support all sort methods.
- LEFT JOIN email_user_history uh ON uh.thread_id = ait.thread_id AND uh.link_id = $1
+ LEFT JOIN email_user_history uh ON uh.thread_id = ait.thread_id AND uh.link_id = tt.link_id
)
SELECT
isk.thread_id as "id!",
@@ -152,7 +153,7 @@ pub(crate) async fn important_preview_cursor(
ORDER BY isk.effective_ts DESC, isk.thread_id DESC
LIMIT $2
"#,
- link_id, // $1
+ link_ids, // $1
query_limit, // $2
cursor_timestamp, // $3
cursor_id, // $4
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/new_inbox.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/new_inbox.rs
index ce07425dfc..cfcf5be0d9 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/new_inbox.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/new_inbox.rs
@@ -10,7 +10,7 @@ use uuid::Uuid;
#[tracing::instrument(skip(pool), err)]
pub(crate) async fn new_inbox_preview_cursor(
pool: &PgPool,
- link_id: &Uuid,
+ link_ids: &[Uuid],
limit: u32,
query: &Query<Uuid, SimpleSortMethod, ()>,
) -> Result<Vec<ThreadPreviewCursorDbRow>, sqlx::Error> {
@@ -21,11 +21,11 @@ pub(crate) async fn new_inbox_preview_cursor(
sqlx::query_as!(
ThreadPreviewCursorDbRow,
r#"
- WITH trash_label AS (
- SELECT id FROM email_labels WHERE link_id = $1 AND name = 'TRASH'
+ WITH trash_labels AS (
+ SELECT id, link_id FROM email_labels WHERE link_id = ANY($1) AND name = 'TRASH'
),
- important_label AS (
- SELECT id FROM email_labels WHERE link_id = $1 AND name = 'IMPORTANT'
+ important_labels AS (
+ SELECT id, link_id FROM email_labels WHERE link_id = ANY($1) AND name = 'IMPORTANT'
)
SELECT
t.id,
@@ -44,8 +44,8 @@ pub(crate) async fn new_inbox_preview_cursor(
SELECT 1
FROM email_messages m_imp
JOIN email_message_labels ml ON m_imp.id = ml.message_id
+ JOIN important_labels il ON ml.label_id = il.id
WHERE m_imp.thread_id = t.id
- AND ml.label_id = (SELECT id FROM important_label)
) AS "is_important!",
c.email_address AS "sender_email?",
COALESCE(lmp.from_name, c.name) AS "sender_name?",
@@ -71,10 +71,10 @@ pub(crate) async fn new_inbox_preview_cursor(
FROM email_threads t
LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id
WHERE
- t.link_id = $1
+ t.link_id = ANY($1)
AND t.inbox_visible = TRUE
AND t.latest_inbound_message_ts IS NOT NULL
-
+
-- The cursor logic is moved inside this subquery for maximum efficiency.
AND (($3::timestamptz IS NULL) OR (
-- This CASE must exactly match the one that defines `effective_ts`
@@ -99,8 +99,8 @@ pub(crate) async fn new_inbox_preview_cursor(
WHERE m.thread_id = t.id
AND NOT EXISTS (
SELECT 1 FROM email_message_labels ml
+ JOIN trash_labels tl ON ml.label_id = tl.id
WHERE ml.message_id = m.id
- AND ml.label_id = (SELECT id FROM trash_label)
)
ORDER BY m.internal_date_ts DESC
LIMIT 1
@@ -111,7 +111,7 @@ pub(crate) async fn new_inbox_preview_cursor(
-- Final ordering is preserved because the input `t` is already sorted.
ORDER BY t.effective_ts DESC, t.updated_at DESC -- fall back to updated_at if effective_ts is the same
"#,
- link_id, // $1
+ link_ids, // $1
query_limit, // $2
cursor_timestamp, // $3
cursor_id, // $4
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/other_inbox.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/other_inbox.rs
index 7ba209bd89..6dbfbb171c 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/other_inbox.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/other_inbox.rs
@@ -9,7 +9,7 @@ use uuid::Uuid;
#[tracing::instrument(skip(pool), err)]
pub(crate) async fn other_inbox_preview_cursor(
pool: &PgPool,
- link_id: &Uuid,
+ link_ids: &[Uuid],
limit: u32,
query: &Query<Uuid, SimpleSortMethod, ()>,
) -> Result<Vec<ThreadPreviewCursorDbRow>, sqlx::Error> {
@@ -69,7 +69,7 @@ pub(crate) async fn other_inbox_preview_cursor(
FROM email_threads t
LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id
WHERE
- t.link_id = $1
+ t.link_id = ANY($1)
AND t.latest_non_spam_message_ts IS NOT NULL
-- Inclusion Criteria: Must have a category label.
AND EXISTS (
@@ -116,7 +116,7 @@ pub(crate) async fn other_inbox_preview_cursor(
JOIN email_links el ON t.link_id = el.id
ORDER BY t.effective_ts DESC, t.updated_at DESC
"#,
- link_id, // $1
+ link_ids, // $1
query_limit, // $2
cursor_timestamp, // $3
cursor_id, // $4
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/sent.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/sent.rs
index 3003325556..9b499d431a 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/sent.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/sent.rs
@@ -10,7 +10,7 @@ use uuid::Uuid;
#[tracing::instrument(skip(pool), err)]
pub(crate) async fn sent_preview_cursor(
pool: &PgPool,
- link_id: &Uuid,
+ link_ids: &[Uuid],
limit: u32,
query: &Query<Uuid, SimpleSortMethod, ()>,
) -> Result<Vec<ThreadPreviewCursorDbRow>, sqlx::Error> {
@@ -70,7 +70,7 @@ pub(crate) async fn sent_preview_cursor(
FROM email_threads t
LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id
WHERE
- t.link_id = $1
+ t.link_id = ANY($1)
AND t.latest_outbound_message_ts IS NOT NULL
-- Cursor logic moved inside for maximum efficiency
@@ -109,7 +109,7 @@ pub(crate) async fn sent_preview_cursor(
-- Final ordering is preserved because the input `t` is already sorted.
ORDER BY t.effective_ts DESC, t.updated_at DESC
"#,
- link_id, // $1
+ link_ids, // $1
query_limit, // $2
cursor_timestamp, // $3
cursor_id, // $4
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/starred.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/starred.rs
index b49e0b0632..51cc359d1a 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/starred.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/starred.rs
@@ -10,7 +10,7 @@ use uuid::Uuid;
#[tracing::instrument(skip(pool), err)]
pub(crate) async fn starred_preview_cursor(
pool: &PgPool,
- link_id: &Uuid,
+ link_ids: &[Uuid],
limit: u32,
query: &Query<Uuid, SimpleSortMethod, ()>,
) -> Result<Vec<ThreadPreviewCursorDbRow>, sqlx::Error> {
@@ -71,11 +71,11 @@ pub(crate) async fn starred_preview_cursor(
-- This sub-subquery efficiently finds the latest starred timestamp for every thread.
SELECT m.thread_id, MAX(m.internal_date_ts) as latest_starred_ts
FROM email_messages m
- WHERE m.link_id = $1 AND m.is_starred = TRUE
+ WHERE m.link_id = ANY($1) AND m.is_starred = TRUE
AND NOT EXISTS (
SELECT 1 FROM email_message_labels ml
JOIN email_labels l ON ml.label_id = l.id
- WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = $1
+ WHERE ml.message_id = m.id AND l.name = 'TRASH' AND l.link_id = m.link_id
)
GROUP BY m.thread_id
) lspt
@@ -117,7 +117,7 @@ pub(crate) async fn starred_preview_cursor(
JOIN email_links el ON t.link_id = el.id
ORDER BY t.effective_ts DESC, t.updated_at DESC
"#,
- link_id, // $1
+ link_ids, // $1
query_limit, // $2
cursor_timestamp, // $3
cursor_id, // $4
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/user_label.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/user_label.rs
index 280351d254..f2356da4cf 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/user_label.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/preview_views/user_label.rs
@@ -10,7 +10,7 @@ use uuid::Uuid;
#[tracing::instrument(skip(pool), err)]
pub(crate) async fn user_label_preview_cursor(
pool: &PgPool,
- link_id: &Uuid,
+ link_ids: &[Uuid],
limit: u32,
query: &Query<Uuid, SimpleSortMethod, ()>,
label_name: &str,
@@ -77,16 +77,16 @@ pub(crate) async fn user_label_preview_cursor(
FROM email_messages m
JOIN email_message_labels ml ON m.id = ml.message_id
JOIN email_labels l ON ml.label_id = l.id
- WHERE m.link_id = $1 AND l.name = $5
+ WHERE m.link_id = ANY($1) AND l.name = $5
AND NOT EXISTS (
SELECT 1 FROM email_message_labels ml2
JOIN email_labels l2 ON ml2.label_id = l2.id
- WHERE ml2.message_id = m.id AND l2.name = 'TRASH' AND l2.link_id = $1
+ WHERE ml2.message_id = m.id AND l2.name = 'TRASH' AND l2.link_id = m.link_id
)
GROUP BY m.thread_id
) llpt
JOIN email_threads t ON llpt.thread_id = t.id
- LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = $1
+ LEFT JOIN email_user_history uh ON uh.thread_id = t.id AND uh.link_id = t.link_id
WHERE
(($3::timestamptz IS NULL) OR (
CASE $6 -- sort_method_str
@@ -123,7 +123,7 @@ pub(crate) async fn user_label_preview_cursor(
JOIN email_links el ON t.link_id = el.id
ORDER BY t.effective_ts DESC, t.updated_at DESC
"#,
- link_id, // $1
+ link_ids, // $1
query_limit, // $2
cursor_timestamp, // $3
cursor_id, // $4
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/test/crm_scope_dynamic_query.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/test/crm_scope_dynamic_query.rs
index 4602e60318..3ff47142ae 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/test/crm_scope_dynamic_query.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/test/crm_scope_dynamic_query.rs
@@ -54,7 +54,7 @@ async fn run_and_collect_ids(
let results = dynamic::dynamic_email_thread_cursor(
pool,
- &link_id,
+ &[link_id],
limit,
&view,
query,
@@ -347,7 +347,7 @@ async fn crm_scope_uses_team_mailboxes_not_caller_link(pool: Pool<Postgres>) ->
let results = dynamic::dynamic_email_thread_cursor(
&pool,
- &carol_link,
+ &[carol_link],
100,
&view,
query,
@@ -650,7 +650,7 @@ async fn crm_scope_pagination_across_team_links(pool: Pool<Postgres>) -> anyhow:
let query_p1 = Query::new(None, SimpleSortMethod::UpdatedAt, filter_p1);
let page1 = dynamic::dynamic_email_thread_cursor(
&pool,
- &link_id,
+ &[link_id],
limit,
&view,
query_p1,
@@ -687,7 +687,7 @@ async fn crm_scope_pagination_across_team_links(pool: Pool<Postgres>) -> anyhow:
let query_p2 = Query::new(Some(cursor), SimpleSortMethod::UpdatedAt, filter_p2);
let page2 = dynamic::dynamic_email_thread_cursor(
&pool,
- &link_id,
+ &[link_id],
limit,
&view,
query_p2,
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/test/dynamic_query.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/test/dynamic_query.rs
index 5b05642caa..9cc01b02c3 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/test/dynamic_query.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/test/dynamic_query.rs
@@ -16,7 +16,7 @@ async fn test_dynamic_query_inbox_view(pool: Pool<Postgres>) -> anyhow::Result<(
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get inbox messages (threads 1, 4, 5, 7)
@@ -51,7 +51,7 @@ async fn test_dynamic_query_sent_view(pool: Pool<Postgres>) -> anyhow::Result<()
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get sent messages (thread 2)
@@ -78,7 +78,7 @@ async fn test_dynamic_query_drafts_view(pool: Pool<Postgres>) -> anyhow::Result<
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get draft messages (threads 3 and 8)
@@ -105,7 +105,7 @@ async fn test_dynamic_query_starred_view(pool: Pool<Postgres>) -> anyhow::Result
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get starred messages (thread 4)
@@ -132,7 +132,7 @@ async fn test_dynamic_query_important_view(pool: Pool<Postgres>) -> anyhow::Resu
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get important messages and drafts (threads 3, 5, and 8)
@@ -168,7 +168,8 @@ async fn test_static_important_query_includes_drafts(pool: Pool<Postgres>) -> an
let query = Query::Sort(SimpleSortMethod::UpdatedAt, ());
let results =
- preview_views::important::important_preview_cursor(&pool, &link_id, limit, &query).await?;
+ preview_views::important::important_preview_cursor(&pool, &[link_id], limit, &query)
+ .await?;
assert_eq!(
results.len(),
@@ -211,7 +212,7 @@ async fn test_dynamic_query_user_label_view(pool: Pool<Postgres>) -> anyhow::Res
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get messages with "Work" label (thread 6)
@@ -240,7 +241,7 @@ async fn test_dynamic_query_with_sender_filter(pool: Pool<Postgres>) -> anyhow::
let query = Query::new(None, SimpleSortMethod::UpdatedAt, email_filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get messages from [email protected] (threads 1, 2, 5)
@@ -275,7 +276,7 @@ async fn test_dynamic_query_with_partial_sender_filter(pool: Pool<Postgres>) ->
let query = Query::new(None, SimpleSortMethod::UpdatedAt, email_filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get all messages since all contacts are from example.com
@@ -303,7 +304,7 @@ async fn test_dynamic_query_with_recipient_filter(pool: Pool<Postgres>) -> anyho
let query = Query::new(None, SimpleSortMethod::UpdatedAt, email_filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get messages to [email protected] (threads 1, 3, 5, 7)
@@ -331,7 +332,7 @@ async fn test_dynamic_query_with_cc_filter(pool: Pool<Postgres>) -> anyhow::Resu
let query = Query::new(None, SimpleSortMethod::UpdatedAt, email_filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get messages with [email protected] in CC (thread 7)
@@ -360,7 +361,7 @@ async fn test_dynamic_query_inbox_with_sender_filter(pool: Pool<Postgres>) -> an
let query = Query::new(None, SimpleSortMethod::UpdatedAt, email_filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get inbox messages from [email protected] (threads 1, 5)
@@ -399,7 +400,7 @@ async fn test_dynamic_query_drafts_with_recipient_filter(
let query = Query::new(None, SimpleSortMethod::UpdatedAt, email_filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get draft messages to [email protected] (threads 3 and 8)
@@ -434,7 +435,7 @@ async fn test_dynamic_query_with_and_filter(pool: Pool<Postgres>) -> anyhow::Res
let query = Query::new(None, SimpleSortMethod::UpdatedAt, email_filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get messages from john to alice (threads 1, 5)
@@ -467,7 +468,7 @@ async fn test_dynamic_query_with_or_filter(pool: Pool<Postgres>) -> anyhow::Resu
let query = Query::new(None, SimpleSortMethod::UpdatedAt, email_filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Should get messages from john or jane
@@ -494,7 +495,7 @@ async fn test_dynamic_query_pagination(pool: Pool<Postgres>) -> anyhow::Result<(
))));
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter1);
let first_page =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
assert_eq!(first_page.len(), 2, "Should return 2 results");
@@ -522,7 +523,7 @@ async fn test_dynamic_query_pagination(pool: Pool<Postgres>) -> anyhow::Result<(
};
let query2 = Query::new(Some(cursor), SimpleSortMethod::UpdatedAt, filter3);
let second_page =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query2, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query2, "", None)
.await?;
assert!(
@@ -567,7 +568,7 @@ async fn test_dynamic_query_with_importance_filter(pool: Pool<Postgres>) -> anyh
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Threads 1 (CATEGORY_PERSONAL), 2 (SENT), 3 (DRAFT), 4 (no depriority), 5 (no depriority), 8 (DRAFT overrides depriority)
@@ -622,7 +623,7 @@ async fn test_dynamic_query_with_importance_filter(pool: Pool<Postgres>) -> anyh
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Threads 6 (CATEGORY_UPDATES) and 7 (CATEGORY_PROMOTIONS)
@@ -671,7 +672,7 @@ async fn test_dynamic_query_importance_true_email_filters_domain_with_address_ov
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -707,7 +708,7 @@ async fn test_dynamic_query_importance_true_email_filters_excludes_trashed_messa
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -739,7 +740,7 @@ async fn test_dynamic_query_importance_false_email_filters_domain_with_address_o
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -775,7 +776,7 @@ async fn test_dynamic_query_with_single_project_id(pool: Pool<Postgres>) -> anyh
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Threads 1, 2, 5 are in Project Alpha
@@ -812,7 +813,7 @@ async fn test_dynamic_query_with_multiple_project_ids(pool: Pool<Postgres>) -> a
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Threads 1, 2, 5 (Alpha) + Thread 6 (Beta)
@@ -854,7 +855,7 @@ async fn test_dynamic_query_project_id_with_sender_filter(
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// All results should be in Project Alpha and from john
@@ -888,7 +889,7 @@ async fn test_dynamic_query_project_id_with_inbox_view(pool: Pool<Postgres>) ->
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
assert_eq!(
@@ -926,7 +927,7 @@ async fn test_dynamic_query_inbox_view_with_importance_false(
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
// Only thread 7: inbox_visible=true AND importance=false
@@ -967,7 +968,7 @@ async fn test_dynamic_query_with_single_thread_id(pool: Pool<Postgres>) -> anyho
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
assert_eq!(results.len(), 1);
@@ -1004,7 +1005,7 @@ async fn test_dynamic_query_thread_id_with_sender_filter(
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
assert_eq!(results.len(), 1);
@@ -1032,7 +1033,7 @@ async fn test_importance_true_includes_drafts_with_depriority_label(
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -1069,7 +1070,7 @@ async fn test_importance_true_excludes_trashed_drafts(pool: Pool<Postgres>) -> a
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -1111,7 +1112,7 @@ async fn test_importance_false_excludes_drafts(pool: Pool<Postgres>) -> anyhow::
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -1161,7 +1162,8 @@ async fn test_static_important_excludes_trashed(pool: Pool<Postgres>) -> anyhow:
let query = Query::Sort(SimpleSortMethod::UpdatedAt, ());
let results =
- preview_views::important::important_preview_cursor(&pool, &link_id, limit, &query).await?;
+ preview_views::important::important_preview_cursor(&pool, &[link_id], limit, &query)
+ .await?;
let result_ids: std::collections::HashSet<String> =
results.iter().map(|r| r.id.to_string()).collect();
@@ -1195,7 +1197,7 @@ async fn test_static_starred_excludes_trashed(pool: Pool<Postgres>) -> anyhow::R
let query = Query::Sort(SimpleSortMethod::UpdatedAt, ());
let results =
- preview_views::starred::starred_preview_cursor(&pool, &link_id, limit, &query).await?;
+ preview_views::starred::starred_preview_cursor(&pool, &[link_id], limit, &query).await?;
let result_ids: std::collections::HashSet<String> =
results.iter().map(|r| r.id.to_string()).collect();
@@ -1230,7 +1232,7 @@ async fn test_static_drafts_excludes_trashed(pool: Pool<Postgres>) -> anyhow::Re
let query = Query::Sort(SimpleSortMethod::UpdatedAt, ());
let results =
- preview_views::draft::drafts_preview_cursor(&pool, &link_id, limit, &query).await?;
+ preview_views::draft::drafts_preview_cursor(&pool, &[link_id], limit, &query).await?;
let result_ids: std::collections::HashSet<String> =
results.iter().map(|r| r.id.to_string()).collect();
@@ -1255,7 +1257,11 @@ async fn test_static_user_label_excludes_trashed(pool: Pool<Postgres>) -> anyhow
let query = Query::Sort(SimpleSortMethod::UpdatedAt, ());
let results = preview_views::user_label::user_label_preview_cursor(
- &pool, &link_id, limit, &query, "Work",
+ &pool,
+ &[link_id],
+ limit,
+ &query,
+ "Work",
)
.await?;
@@ -1296,7 +1302,7 @@ async fn test_shared_exclude_returns_only_own_threads(pool: Pool<Postgres>) -> a
let results = dynamic::dynamic_email_thread_cursor(
&pool,
- &link_id,
+ &[link_id],
limit,
&view,
query,
@@ -1349,7 +1355,7 @@ async fn test_shared_only_returns_only_shared_threads(pool: Pool<Postgres>) -> a
let results = dynamic::dynamic_email_thread_cursor(
&pool,
- &link_id,
+ &[link_id],
limit,
&view,
query,
@@ -1414,7 +1420,7 @@ async fn test_shared_include_returns_own_and_shared_threads(
let results = dynamic::dynamic_email_thread_cursor(
&pool,
- &link_id,
+ &[link_id],
limit,
&view,
query,
@@ -1475,7 +1481,7 @@ async fn test_dynamic_query_calendar_only_filter(pool: Pool<Postgres>) -> anyhow
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -1541,7 +1547,7 @@ async fn test_dynamic_query_calendar_only_inbox_view(pool: Pool<Postgres>) -> an
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -1591,7 +1597,7 @@ async fn test_dynamic_query_calendar_only_combined_with_sender(
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -1633,14 +1639,16 @@ async fn test_dynamic_query_calendar_only_false_is_noop(
))),
));
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None).await?
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
+ .await?
};
let baseline = {
let filter = Arc::new(Expr::Literal(EmailLiteral::Sender(Email::Partial(
"example.com".to_string(),
))));
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None).await?
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
+ .await?
};
let with_false_ids: std::collections::HashSet<_> = with_false.iter().map(|r| r.id).collect();
@@ -1668,7 +1676,7 @@ async fn test_shared_only_returns_correct_owner_id(pool: Pool<Postgres>) -> anyh
let results = dynamic::dynamic_email_thread_cursor(
&pool,
- &link_id,
+ &[link_id],
limit,
&view,
query,
@@ -1714,7 +1722,7 @@ async fn test_dynamic_query_short_circuits_on_unresolved_complete_email(
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
assert!(
@@ -1749,7 +1757,7 @@ async fn test_dynamic_query_with_bcc_filter(pool: Pool<Postgres>) -> anyhow::Res
let query = Query::new(None, SimpleSortMethod::UpdatedAt, email_filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -1804,7 +1812,7 @@ async fn test_dynamic_query_and_filter_uses_single_message_semantics(
))));
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let ids: std::collections::HashSet<String> =
results.iter().map(|r| r.id.to_string()).collect();
@@ -1826,7 +1834,7 @@ async fn test_dynamic_query_and_filter_uses_single_message_semantics(
));
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let ids: std::collections::HashSet<String> = results.iter().map(|r| r.id.to_string()).collect();
@@ -1889,7 +1897,7 @@ async fn test_dynamic_query_updated_at_greater_than(pool: Pool<Postgres>) -> any
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -1942,7 +1950,7 @@ async fn test_dynamic_query_updated_at_less_than(pool: Pool<Postgres>) -> anyhow
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -1999,7 +2007,7 @@ async fn test_dynamic_query_updated_at_greater_than_or_equal(
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -2053,7 +2061,7 @@ async fn test_dynamic_query_updated_at_less_than_or_equal(
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -2099,7 +2107,7 @@ async fn test_dynamic_query_created_at_greater_than(pool: Pool<Postgres>) -> any
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -2144,7 +2152,7 @@ async fn test_dynamic_query_created_at_less_than(pool: Pool<Postgres>) -> anyhow
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -2204,7 +2212,7 @@ async fn test_dynamic_query_date_range_combined(pool: Pool<Postgres>) -> anyhow:
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -2269,7 +2277,7 @@ async fn test_dynamic_query_date_with_sender_filter(pool: Pool<Postgres>) -> any
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -2319,7 +2327,7 @@ async fn test_dynamic_query_date_with_inbox_view(pool: Pool<Postgres>) -> anyhow
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
@@ -2382,7 +2390,7 @@ async fn test_dynamic_query_created_at_and_updated_at_combined(
let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
let results =
- dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query, "", None)
+ dynamic::dynamic_email_thread_cursor(&pool, &[link_id], limit, &view, query, "", None)
.await?;
let result_ids: std::collections::HashSet<String> =
diff --git a/rust/cloud-storage/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs b/rust/cloud-storage/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs
index b79af3d983..1bccc931e4 100644
--- a/rust/cloud-storage/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs
+++ b/rust/cloud-storage/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs
@@ -650,7 +650,7 @@ async fn filter_notifiable_message(
let query = PreviewCursorQuery {
view: PreviewView::StandardLabel(PreviewViewStandardLabel::Inbox),
- link_id: link.id,
+ link_ids: vec![link.id],
limit: 1,
query: models_pagination::Query::Sort(
models_pagination::SimpleSortMethod::UpdatedAt,
diff --git a/rust/cloud-storage/item_filters/src/ast/email.rs b/rust/cloud-storage/item_filters/src/ast/email.rs
index 3a29c9e56c..4b0d041aef 100644
--- a/rust/cloud-storage/item_filters/src/ast/email.rs
+++ b/rust/cloud-storage/item_filters/src/ast/email.rs
@@ -44,6 +44,10 @@ pub enum EmailLiteral {
Recipient(Email),
/// This value filters by email thread ID
ThreadId(Uuid),
+ /// Restrict to a specific inbox (email_links.id, which is also
+ /// email_threads.link_id). Multiple `Owner` literals OR together to
+ /// narrow the search to a subset of the user's inboxes.
+ Owner(Uuid),
/// This value filters by project ID
ProjectId(String),
/// This node value filters by email importance. false short-circuits to match nothing.
@@ -75,6 +79,7 @@ impl ExpandFrame<EmailLiteral> for EmailFilters {
bcc,
recipients,
email_thread_ids,
+ link_ids,
project_ids,
importance,
notification_filters,
@@ -122,6 +127,11 @@ impl ExpandFrame<EmailLiteral> for EmailFilters {
.map(|s| Uuid::parse_str(s))
.try_expand(|r| r.map(EmailLiteral::ThreadId), Expr::or)?;
+ let owner_nodes = link_ids
+ .iter()
+ .map(|s| Uuid::parse_str(s))
+ .try_expand(|r| r.map(EmailLiteral::Owner), Expr::or)?;
+
let project_id_nodes = project_ids
.into_iter()
.expand(EmailLiteral::ProjectId, Expr::or);
@@ -148,6 +158,7 @@ impl ExpandFrame<EmailLiteral> for EmailFilters {
bcc_nodes,
recipient_nodes,
thread_id_nodes,
+ owner_nodes,
project_id_nodes,
importance_node,
notification_done_node,
diff --git a/rust/cloud-storage/item_filters/src/lib.rs b/rust/cloud-storage/item_filters/src/lib.rs
index 0ce9108e4b..ec27a36635 100644
--- a/rust/cloud-storage/item_filters/src/lib.rs
+++ b/rust/cloud-storage/item_filters/src/lib.rs
@@ -218,6 +218,11 @@ pub struct EmailFilters {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub email_thread_ids: Vec<String>,
+ /// Restrict to specific inboxes by email_links.id. Empty means "any inbox the
+ /// caller can access" (soup expands to the full set at the router edge).
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ pub link_ids: Vec<String>,
+
/// A list of project ids to search within. Empty to ignore project filtering.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub project_ids: Vec<String>,
@@ -280,6 +285,7 @@ impl IsEmpty for EmailFilters {
bcc,
recipients,
email_thread_ids,
+ link_ids,
project_ids,
importance,
notification_filters,
@@ -295,6 +301,7 @@ impl IsEmpty for EmailFilters {
&& bcc.is_empty()
&& recipients.is_empty()
&& email_thread_ids.is_empty()
+ && link_ids.is_empty()
&& project_ids.is_empty()
&& importance.is_none()
&& notification_filters.is_empty()
diff --git a/rust/cloud-storage/soup/src/domain/models.rs b/rust/cloud-storage/soup/src/domain/models.rs
index 93f644fd3c..796ed4ee0c 100644
--- a/rust/cloud-storage/soup/src/domain/models.rs
+++ b/rust/cloud-storage/soup/src/domain/models.rs
@@ -214,7 +214,10 @@ pub struct SoupRequest<T> {
pub cursor: SoupQuery<T>,
pub user: MacroUserIdStr<'static>,
pub email_preview_view: PreviewView,
- pub link_id: Option<Uuid>,
+ /// Every inbox the caller can read (own + delegated via macro_user_links).
+ /// Empty when the caller has no inboxes — `build_email_request` returns
+ /// `None` so the email branch is skipped.
+ pub link_ids: Vec<Uuid>,
}
/// trait which defines a type which can be fallibly converted into a SoupRequest with ast
@@ -231,7 +234,7 @@ impl IntoSoupReqAst for SoupRequest<EntityFilters> {
cursor,
user,
email_preview_view,
- link_id,
+ link_ids,
} = self;
Ok(SoupRequest {
@@ -240,7 +243,7 @@ impl IntoSoupReqAst for SoupRequest<EntityFilters> {
cursor: cursor.into_ast()?,
user,
email_preview_view,
- link_id,
+ link_ids,
})
}
}
@@ -253,7 +256,7 @@ impl IntoSoupReqAst for SoupRequest<EntityFilterAst> {
cursor,
user,
email_preview_view,
- link_id,
+ link_ids,
} = self;
Ok(SoupRequest {
@@ -262,7 +265,7 @@ impl IntoSoupReqAst for SoupRequest<EntityFilterAst> {
cursor: cursor.map(|f| if f.is_empty() { None } else { Some(f) }),
user,
email_preview_view,
- link_id,
+ link_ids,
})
}
}
@@ -296,9 +299,13 @@ impl SoupRequest<Option<EntityFilterAst>> {
};
let crm_scope = entity_ast.and_then(|a| a.email_filter.crm_scope.clone());
+ if self.link_ids.is_empty() {
+ return None;
+ }
+
Some(GetEmailsRequest {
view: self.email_preview_view.clone(),
- link_id: self.link_id?,
+ link_ids: self.link_ids.clone(),
macro_id: self.user.clone(),
limit: Some(self.limit as u32),
query: match &self.cursor {
diff --git a/rust/cloud-storage/soup/src/domain/service/tests.rs b/rust/cloud-storage/soup/src/domain/service/tests.rs
index cb5cba6add..c6c9402118 100644
--- a/rust/cloud-storage/soup/src/domain/service/tests.rs
+++ b/rust/cloud-storage/soup/src/domain/service/tests.rs
@@ -436,7 +436,7 @@ async fn simple_soup_includes_foreign_entities() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: None,
+ link_ids: vec![],
soup_type: SoupType::UnExpanded,
limit: 20,
cursor: SoupQuery::new_sort_simple(
@@ -517,7 +517,7 @@ async fn frecency_soup_does_not_query_foreign_entities() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: None,
+ link_ids: vec![],
soup_type: SoupType::UnExpanded,
limit: 20,
cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),
@@ -563,7 +563,7 @@ async fn team_receipt_contributes_team_foreign_entity_source_id() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: None,
+ link_ids: vec![],
soup_type: SoupType::UnExpanded,
limit: 20,
cursor: SoupQuery::new_sort_simple(
@@ -619,7 +619,7 @@ async fn foreign_entity_filter_suppresses_non_matching_foreign_entities() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: None,
+ link_ids: vec![],
soup_type: SoupType::UnExpanded,
limit: 20,
cursor: SoupQuery::new_sort_simple(
@@ -692,7 +692,7 @@ async fn it_should_not_query_frecency() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: 0,
cursor: SoupQuery::new_sort_simple(
@@ -779,7 +779,7 @@ async fn it_should_query_frecency() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: u16::MAX,
cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),
@@ -863,7 +863,7 @@ async fn it_should_sort_frecency_descending() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: u16::MAX,
cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),
@@ -961,7 +961,7 @@ async fn frecency_should_fallback() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: 100,
cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),
@@ -1043,7 +1043,7 @@ async fn frecency_should_paginate() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: 100,
cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),
@@ -1127,7 +1127,7 @@ async fn frecency_should_resume_cursor() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: 100,
cursor: SoupQuery::new_cursor_frecency(CursorWithValAndFilter {
@@ -1227,7 +1227,7 @@ async fn frecency_fallback_cursor_should_resume() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: 100,
cursor: SoupQuery::new_cursor_frecency(CursorWithValAndFilter {
@@ -1303,7 +1303,7 @@ async fn cursor_should_return_simple_sort() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: 0,
cursor: SoupQuery::new_sort_simple(
@@ -1375,7 +1375,7 @@ async fn cursor_should_return_frecency() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: 100,
cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),
@@ -1437,7 +1437,7 @@ async fn it_should_return_is_completed_true_for_completed_tasks() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: 0,
cursor: SoupQuery::new_sort_simple(
@@ -1489,7 +1489,7 @@ async fn it_should_return_is_completed_false_for_incomplete_tasks() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: 0,
cursor: SoupQuery::new_sort_simple(
@@ -1541,7 +1541,7 @@ async fn it_should_return_is_completed_none_for_non_tasks() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: 0,
cursor: SoupQuery::new_sort_simple(
@@ -1605,7 +1605,7 @@ async fn it_should_preserve_is_completed_for_mixed_items() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: 0,
cursor: SoupQuery::new_sort_simple(
@@ -1688,7 +1688,7 @@ async fn it_should_preserve_is_completed_in_by_ids_queries() {
email_preview_view: PreviewView::StandardLabel(
email::domain::models::PreviewViewStandardLabel::Inbox,
),
- link_id: Some(Uuid::new_v4()),
+ link_ids: vec![Uuid::new_v4()],
soup_type: SoupType::UnExpanded,
limit: 3,
cursor: SoupQuery::new_sort_frecency(Frecency, EntityFilters::default()),
diff --git a/rust/cloud-storage/soup/src/inbound/axum_router.rs b/rust/cloud-storage/soup/src/inbound/axum_router.rs
index 3eac2a8827..0b22d9ec95 100644
--- a/rust/cloud-storage/soup/src/inbound/axum_router.rs
+++ b/rust/cloud-storage/soup/src/inbound/axum_router.rs
@@ -15,13 +15,10 @@ use axum::{
use axum_extra::{either::Either, extract::Cached};
use email::{
domain::{
- models::{Link, PreviewView},
+ models::{EmailErr, PreviewView},
ports::EmailService,
},
- inbound::axum::{
- axum_impls::{EmailLinkErr, EmailLinkExtractor},
- previews_router::EmailRouterState,
- },
+ inbound::axum::previews_router::EmailRouterState,
};
use entity_access::{
domain::{
@@ -313,7 +310,7 @@ where
async fn handle<R>(
&self,
macro_user_id: MacroUserIdStr<'static>,
- email_link: Option<Link>,
+ link_ids: Vec<Uuid>,
team_receipt_option: Option<EntityAccessReceipt<MemberTeamRole>>,
ApiSoupRequestInner {
filters,
@@ -369,7 +366,7 @@ where
cursor,
user: macro_user_id,
email_preview_view: email_view,
- link_id: email_link.map(|l| l.id),
+ link_ids,
},
team_receipt,
)
@@ -546,7 +543,7 @@ pub enum SoupHandlerErr {
#[error("An internal server error has occurred")]
Internal(SoupErr),
#[error("An internal email server error has occurred")]
- EmailLinkErr(#[from] EmailLinkErr),
+ EmailErr(#[from] EmailErr),
#[error("Invalid filter arguments provided")]
ExpandErr(ExpandErr),
#[error("Invalid compound filter could not be expanded")]
@@ -585,6 +582,28 @@ impl IntoResponse for SoupHandlerErr {
}
}
+async fn fetch_caller_link_ids<T, U, EAS>(
+ service: &SoupRouterState<T, U, EAS>,
+ macro_user_id: &str,
+) -> Result<Vec<Uuid>, SoupHandlerErr>
+where
+ T: SoupService,
+ U: EmailService,
+ EAS: EntityAccessService,
+{
+ let macro_id = MacroUserIdStr::parse_from_str(macro_user_id).map_err(|e| {
+ SoupHandlerErr::Internal(SoupErr::SoupDbErr(anyhow::anyhow!(
+ "invalid macro_user_id from extractor: {e}"
+ )))
+ })?;
+ let links = service
+ .email
+ .service()
+ .get_inboxes_for_macro_id(macro_id)
+ .await?;
+ Ok(links.into_iter().map(|l| l.id).collect())
+}
+
/// Gets the items the user has access to
#[utoipa::path(
get,
@@ -603,7 +622,6 @@ impl IntoResponse for SoupHandlerErr {
pub async fn get_soup_handler<T, U, EAS>(
State(service): State<SoupRouterState<T, U, EAS>>,
Cached(MacroUserExtractor { macro_user_id, .. }): Cached<MacroUserExtractor>,
- email_link: Result<Cached<EmailLinkExtractor<U>>, EmailLinkErr>,
team: OptionalMacroUserTeamExtractor<MemberTeamRole, EAS>,
Query(params): Query<Params>,
cursor: SoupCursor<EntityFilters>,
@@ -613,18 +631,14 @@ where
U: EmailService,
EAS: EntityAccessService,
{
- let link = match email_link {
- Ok(l) => Some(l.0.0),
- Err(EmailLinkErr::NotFound) => None,
- Err(e) => Err(e)?,
- };
+ let link_ids = fetch_caller_link_ids(&service, macro_user_id.as_ref()).await?;
// Team receipt is plumbed through even for GET so that paginating a
// team-scoped query via a cursor (which carries the original filter)
// continues to authorize correctly.
service
.handle(
macro_user_id,
- link,
+ link_ids,
team.entity_access_receipt,
ApiSoupRequestInner {
params,
@@ -678,7 +692,6 @@ type SoupCursor<R> = axum_extra::either::Either<
pub async fn post_soup_handler<T, U, EAS>(
State(service): State<SoupRouterState<T, U, EAS>>,
Cached(MacroUserExtractor { macro_user_id, .. }): Cached<MacroUserExtractor>,
- email_link: Result<Cached<EmailLinkExtractor<U>>, EmailLinkErr>,
team: OptionalMacroUserTeamExtractor<MemberTeamRole, EAS>,
cursor: SoupCursor<EntityFilters>,
Json(PostSoupRequest {
@@ -692,18 +705,14 @@ where
U: EmailService,
EAS: EntityAccessService,
{
- let link = match email_link {
- Ok(l) => Some(l.0.0),
- Err(EmailLinkErr::NotFound) => None,
- Err(e) => Err(e)?,
- };
+ let link_ids = fetch_caller_link_ids(&service, macro_user_id.as_ref()).await?;
// Pass the raw extractor receipt through — `handle` resolves the
// CRM-scope check against the *effective* filter (which may come from
// the cursor on follow-up pages), not the request body.
service
.handle(
macro_user_id,
- link,
+ link_ids,
team.entity_access_receipt,
ApiSoupRequestInner {
filters,
@@ -747,7 +756,6 @@ pub struct PostSoupAstRequest {
pub async fn post_soup_ast_handler<T, U, EAS>(
State(service): State<SoupRouterState<T, U, EAS>>,
Cached(MacroUserExtractor { macro_user_id, .. }): Cached<MacroUserExtractor>,
- email_link: Result<Cached<EmailLinkExtractor<U>>, EmailLinkErr>,
team: OptionalMacroUserTeamExtractor<MemberTeamRole, EAS>,
cursor: SoupCursor<ApiEntityFilterAst>,
Json(PostSoupAstRequest {
@@ -761,18 +769,14 @@ where
U: EmailService,
EAS: EntityAccessService,
{
- let link = match email_link {
- Ok(l) => Some(l.0.0),
- Err(EmailLinkErr::NotFound) => None,
- Err(e) => Err(e)?,
- };
+ let link_ids = fetch_caller_link_ids(&service, macro_user_id.as_ref()).await?;
// Pass the raw extractor receipt through — `handle` resolves the
// CRM-scope check against the *effective* filter (which may come from
// the cursor on follow-up pages), not the request body.
service
.handle(
macro_user_id,
- link,
+ link_ids,
team.entity_access_receipt,
ApiSoupRequestInner {
filters,
@@ -966,7 +970,7 @@ impl IntoSoupReqAst for SoupRequest<ApiEntityFilterAst> {
cursor,
user,
email_preview_view,
- link_id,
+ link_ids,
} = self;
let cursor = match cursor {
@@ -986,7 +990,7 @@ impl IntoSoupReqAst for SoupRequest<ApiEntityFilterAst> {
cursor,
user,
email_preview_view,
- link_id,
+ link_ids,
})
}
}
diff --git a/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs b/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs
index 97c930573a..3bf1570a16 100644
--- a/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs
+++ b/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs
@@ -50,7 +50,7 @@ enum MockCursorKind {
struct MockSoupCall {
soup_type: SoupType,
email_preview_view: PreviewView,
- link_id: Option<Uuid>,
+ link_ids: Vec<Uuid>,
cursor_kind: MockCursorKind,
filter: serde_json::Value,
expanded_filter: serde_json::Value,
@@ -95,14 +95,14 @@ impl SoupService for MockSoup {
};
let soup_type = req.soup_type;
let email_preview_view = req.email_preview_view.clone();
- let link_id = req.link_id;
+ let link_ids = req.link_ids.clone();
let filter = serde_json::to_value(req.cursor.filter()).unwrap();
let expanded_filter = serde_json::to_value(req.into_ast()?.cursor.filter()).unwrap();
let mut guard = self.called.lock().unwrap();
guard.push(MockSoupCall {
soup_type,
email_preview_view,
- link_id,
+ link_ids,
cursor_kind,
filter,
expanded_filter,
@@ -160,6 +160,13 @@ impl EmailService for MockEmail {
Err(EmailErr::RepoErr(anyhow::anyhow!("Not implemented")))
}
+ async fn get_inboxes_for_macro_id(
+ &self,
+ _macro_id: macro_user_id::user_id::MacroUserIdStr<'_>,
+ ) -> Result<Vec<email::domain::models::Link>, email::domain::models::EmailErr> {
+ Ok(Vec::new())
+ }
+
async fn get_thread_with_messages(
&self,
_receipt: EntityAccessReceipt<ViewAccessLevel>,
@@ -434,6 +441,13 @@ impl EmailService for MockEmailLinkResult {
Err(EmailErr::RepoErr(anyhow::anyhow!("Not implemented")))
}
+ async fn get_inboxes_for_macro_id(
+ &self,
+ _macro_id: macro_user_id::user_id::MacroUserIdStr<'_>,
+ ) -> Result<Vec<email::domain::models::Link>, email::domain::models::EmailErr> {
+ (self.get_link_result)().map(|opt| opt.into_iter().collect())
+ }
+
async fn get_thread_with_messages(
&self,
_receipt: EntityAccessReceipt<ViewAccessLevel>,
@@ -548,7 +562,7 @@ async fn it_calls_soup_with_missing_link() {
let guard = inner_counter.lock().unwrap();
assert_eq!(guard.len(), 1);
- assert!(guard.first().unwrap().link_id.is_none())
+ assert!(guard.first().unwrap().link_ids.is_empty())
}
#[tokio::test]
@@ -1523,7 +1537,7 @@ fn ast_endpoint_email_crm_domains_stamps_scope_and_ands_into_tree() {
))),
user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
email_preview_view: PreviewView::StandardLabel(PreviewViewStandardLabel::Inbox),
- link_id: None,
+ link_ids: vec![],
};
let req: SoupRequest<Option<EntityFilterAst>> = req.into_ast().unwrap();
let ast = match &req.cursor {
@@ -1551,7 +1565,7 @@ fn ast_endpoint_email_crm_addresses_stamps_scope() {
))),
user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
email_preview_view: PreviewView::StandardLabel(PreviewViewStandardLabel::Inbox),
- link_id: None,
+ link_ids: vec![],
};
let req: SoupRequest<Option<EntityFilterAst>> = req.into_ast().unwrap();
let ast = match &req.cursor {
@@ -1579,7 +1593,7 @@ fn ast_endpoint_email_crm_both_lists_rejected() {
))),
user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
email_preview_view: PreviewView::StandardLabel(PreviewViewStandardLabel::Inbox),
- link_id: None,
+ link_ids: vec![],
};
let res = req.into_ast();
assert!(res.is_err(), "mutual exclusivity must reject both lists");
@@ -1600,7 +1614,7 @@ fn ast_endpoint_empty_crm_lists_leaves_scope_none() {
))),
user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
email_preview_view: PreviewView::StandardLabel(PreviewViewStandardLabel::Inbox),
- link_id: None,
+ link_ids: vec![],
};
let req: SoupRequest<Option<EntityFilterAst>> = req.into_ast().unwrap();
// ast.is_none() because the whole filter is empty.
@@ -1634,7 +1648,7 @@ fn ast_endpoint_crm_ands_with_existing_freeform_ef() {
))),
user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
email_preview_view: PreviewView::StandardLabel(PreviewViewStandardLabel::Inbox),
- link_id: None,
+ link_ids: vec![],
};
let req: SoupRequest<Option<EntityFilterAst>> = req.into_ast().unwrap();
let ast = match &req.cursor {
@@ -1689,7 +1703,7 @@ fn ast_endpoint_crm_domains_are_lowercased_in_scope() {
))),
user: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
email_preview_view: PreviewView::StandardLabel(PreviewViewStandardLabel::Inbox),
- link_id: None,
+ link_ids: vec![],
};
let req: SoupRequest<Option<EntityFilterAst>> = req.into_ast().unwrap();
let ast = match &req.cursor {
diff --git a/rust/cloud-storage/soup/src/inbound/toolset/list_entities.rs b/rust/cloud-storage/soup/src/inbound/toolset/list_entities.rs
index bc3ace6dd8..5bb72f37dd 100644
--- a/rust/cloud-storage/soup/src/inbound/toolset/list_entities.rs
+++ b/rust/cloud-storage/soup/src/inbound/toolset/list_entities.rs
@@ -374,15 +374,17 @@ where
.unwrap_or(RESULT_LIMIT)
.clamp(1, MAX_RESULT_LIMIT);
- let link_id = service_context
+ let link_ids: Vec<uuid::Uuid> = service_context
.email_service
- .get_link_by_macro_id(request_context.user_id.copied())
+ .get_inboxes_for_macro_id(request_context.user_id.copied())
.await
.map_err(|e| ToolCallError {
- description: format!("Failed to resolve email link: {e}"),
+ description: format!("Failed to resolve email links: {e}"),
internal_error: e.into(),
})?
- .map(|link| link.id);
+ .into_iter()
+ .map(|link| link.id)
+ .collect();
let result = service_context
.service
@@ -393,7 +395,7 @@ where
cursor: SoupQuery::new_sort_simple(sort_method, filters),
user: request_context.user_id,
email_preview_view,
- link_id,
+ link_ids,
},
None,
)