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.

perf(soup): serve NOTIFIED_AT on GraphQL soup and check by-ids access per id (#8450)

teo21496a5a82d5
diff --git a/.sqlx/query-0e9b262983e40207c6c0dcce3e7948837e27fdde34109b1aac0d889f10a25eed.json b/.sqlx/query-0e9b262983e40207c6c0dcce3e7948837e27fdde34109b1aac0d889f10a25eed.json
deleted file mode 100644
index 74b278145b..0000000000
--- a/.sqlx/query-0e9b262983e40207c6c0dcce3e7948837e27fdde34109b1aac0d889f10a25eed.json
+++ /dev/null
@@ -1,165 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL::text as \"model\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n EXISTS (\n SELECT 1\n FROM document_email de\n WHERE de.document_id = d.id\n ) as \"is_email_attachment!\",\n (\n dt.sub_type IS DISTINCT FROM 'task'\n OR EXISTS (\n SELECT 1\n FROM entity_properties ep_assignees\n WHERE ep_assignees.entity_id = d.id\n AND ep_assignees.entity_type = 'TASK'\n AND ep_assignees.property_definition_id = $6\n AND ep_assignees.values->'value' @> jsonb_build_array(\n jsonb_build_object('entity_id', $1)\n )\n )\n ) as \"is_important!\",\n ARRAY(\n SELECT status_option_id::uuid\n FROM jsonb_array_elements_text(\n CASE\n WHEN jsonb_typeof(ep_status.values->'value') = 'array'\n THEN ep_status.values->'value'\n ELSE '[]'::jsonb\n END\n ) AS status_option_id\n ) as \"status_option_ids!: Vec<Uuid>\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $4\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status \n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id \n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $5\n INNER JOIN UserAccessibleItems uai \n ON uai.item_id = d.id \n AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh \n ON uh.\"itemId\" = d.id \n AND uh.\"itemType\" = 'document' \n AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id \n FROM \"DocumentBom\" b \n WHERE b.\"documentId\" = d.id \n ORDER BY b.\"createdAt\" DESC \n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha \n FROM \"DocumentInstance\" i \n WHERE i.\"documentId\" = d.id \n ORDER BY i.\"updatedAt\" DESC \n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n AND d.id = ANY($2::text[])\n\n UNION ALL\n \n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n c.model as \"model\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n false as \"is_email_attachment!\",\n true as \"is_important!\",\n ARRAY[]::uuid[] as \"status_option_ids!: Vec<Uuid>\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = c.id\n AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id\n AND uh.\"itemType\" = 'chat'\n AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n AND c.id = ANY($3::text[])\n )\n SELECT * \n FROM Combined\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_type!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "id!",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "document_version_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "user_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "name!",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "branched_from_id",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "branched_from_version_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 7,
- "name": "document_family_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 8,
- "name": "file_type",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 11,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "is_persistent",
- "type_info": "Bool"
- },
- {
- "ordinal": 13,
- "name": "model",
- "type_info": "Text"
- },
- {
- "ordinal": 14,
- "name": "sha",
- "type_info": "Text"
- },
- {
- "ordinal": 15,
- "name": "sub_type?: DocumentSubType",
- "type_info": {
- "Custom": {
- "name": "document_sub_type_value",
- "kind": {
- "Enum": [
- "task",
- "snippet",
- "skill",
- "initiative_description"
- ]
- }
- }
- }
- },
- {
- "ordinal": 16,
- "name": "is_email_attachment!",
- "type_info": "Bool"
- },
- {
- "ordinal": 17,
- "name": "is_important!",
- "type_info": "Bool"
- },
- {
- "ordinal": 18,
- "name": "status_option_ids!: Vec<Uuid>",
- "type_info": "UuidArray"
- },
- {
- "ordinal": 19,
- "name": "viewed_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 20,
- "name": "is_completed",
- "type_info": "Bool"
- },
- {
- "ordinal": 21,
- "name": "deleted_at",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "TextArray",
- "TextArray",
- "Text",
- "Uuid",
- "Uuid"
- ]
- },
- "nullable": [
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "0e9b262983e40207c6c0dcce3e7948837e27fdde34109b1aac0d889f10a25eed"
-}
diff --git a/.sqlx/query-16dca24944ad6d29aa1011d5b2b18d964fe1d31ffaef2982499c24f04c2a9c03.json b/.sqlx/query-16dca24944ad6d29aa1011d5b2b18d964fe1d31ffaef2982499c24f04c2a9c03.json
new file mode 100644
index 0000000000..2a9cbaa937
--- /dev/null
+++ b/.sqlx/query-16dca24944ad6d29aa1011d5b2b18d964fe1d31ffaef2982499c24f04c2a9c03.json
@@ -0,0 +1,165 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL::text as \"model\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n EXISTS (\n SELECT 1\n FROM document_email de\n WHERE de.document_id = d.id\n ) as \"is_email_attachment!\",\n (\n dt.sub_type IS DISTINCT FROM 'task'\n OR EXISTS (\n SELECT 1\n FROM entity_properties ep_assignees\n WHERE ep_assignees.entity_id = d.id\n AND ep_assignees.entity_type = 'TASK'\n AND ep_assignees.property_definition_id = $6\n AND ep_assignees.values->'value' @> jsonb_build_array(\n jsonb_build_object('entity_id', $1)\n )\n )\n ) as \"is_important!\",\n ARRAY(\n SELECT status_option_id::uuid\n FROM jsonb_array_elements_text(\n CASE\n WHEN jsonb_typeof(ep_status.values->'value') = 'array'\n THEN ep_status.values->'value'\n ELSE '[]'::jsonb\n END\n ) AS status_option_id\n ) as \"status_option_ids!: Vec<Uuid>\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $4\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status \n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id \n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $5\n LEFT JOIN \"UserHistory\" uh \n ON uh.\"itemId\" = d.id \n AND uh.\"itemType\" = 'document' \n AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id \n FROM \"DocumentBom\" b \n WHERE b.\"documentId\" = d.id \n ORDER BY b.\"createdAt\" DESC \n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha \n FROM \"DocumentInstance\" i \n WHERE i.\"documentId\" = d.id \n ORDER BY i.\"updatedAt\" DESC \n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n AND d.id = ANY($2::text[])\n AND EXISTS (\n SELECT 1 FROM entity_access ea\n WHERE ea.entity_id::text = d.id\n AND ea.entity_type = 'document'\n AND ea.source_id = ANY(ARRAY(SELECT source_id FROM user_source_ids))\n )\n\n UNION ALL\n \n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n c.model as \"model\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n false as \"is_email_attachment!\",\n true as \"is_important!\",\n ARRAY[]::uuid[] as \"status_option_ids!: Vec<Uuid>\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id\n AND uh.\"itemType\" = 'chat'\n AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n AND c.id = ANY($3::text[])\n AND EXISTS (\n SELECT 1 FROM entity_access ea\n WHERE ea.entity_id::text = c.id\n AND ea.entity_type = 'chat'\n AND ea.source_id = ANY(ARRAY(SELECT source_id FROM user_source_ids))\n )\n )\n SELECT * \n FROM Combined\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 13,
+ "name": "model",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 15,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task",
+ "snippet",
+ "skill",
+ "initiative_description"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 16,
+ "name": "is_email_attachment!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 17,
+ "name": "is_important!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 18,
+ "name": "status_option_ids!: Vec<Uuid>",
+ "type_info": "UuidArray"
+ },
+ {
+ "ordinal": 19,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 20,
+ "name": "is_completed",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 21,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "TextArray",
+ "Text",
+ "Uuid",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "16dca24944ad6d29aa1011d5b2b18d964fe1d31ffaef2982499c24f04c2a9c03"
+}
diff --git a/.sqlx/query-225fa012f7e8731c67488221e06333f87800b8b96970638e21b3f5ce8a58511f.json b/.sqlx/query-225fa012f7e8731c67488221e06333f87800b8b96970638e21b3f5ce8a58511f.json
deleted file mode 100644
index 3985ea209d..0000000000
--- a/.sqlx/query-225fa012f7e8731c67488221e06333f87800b8b96970638e21b3f5ce8a58511f.json
+++ /dev/null
@@ -1,153 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\", \n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL::text as \"model\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n d.\"updatedAt\"::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $5\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $6\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = d.id\n AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = d.id\n AND uh.\"itemType\" = 'document'\n AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n AND d.id = ANY($2::text[])\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n c.model as \"model\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n c.\"updatedAt\"::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = c.id\n AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id\n AND uh.\"itemType\" = 'chat'\n AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n AND c.id = ANY($3::text[])\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL::text as \"model\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n p.\"updatedAt\"::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = p.id\n AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id\n AND uh.\"itemType\" = 'project'\n AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n AND p.id = ANY($4::text[])\n )\n SELECT * \n FROM Combined\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_type!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "id!",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "document_version_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "user_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "name!",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "branched_from_id",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "branched_from_version_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 7,
- "name": "document_family_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 8,
- "name": "file_type",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 11,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "is_persistent",
- "type_info": "Bool"
- },
- {
- "ordinal": 13,
- "name": "model",
- "type_info": "Text"
- },
- {
- "ordinal": 14,
- "name": "sha",
- "type_info": "Text"
- },
- {
- "ordinal": 15,
- "name": "sub_type?: DocumentSubType",
- "type_info": {
- "Custom": {
- "name": "document_sub_type_value",
- "kind": {
- "Enum": [
- "task",
- "snippet",
- "skill",
- "initiative_description"
- ]
- }
- }
- }
- },
- {
- "ordinal": 16,
- "name": "viewed_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 17,
- "name": "sort_ts!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 18,
- "name": "is_completed",
- "type_info": "Bool"
- },
- {
- "ordinal": 19,
- "name": "deleted_at",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "TextArray",
- "TextArray",
- "TextArray",
- "Text",
- "Uuid"
- ]
- },
- "nullable": [
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "225fa012f7e8731c67488221e06333f87800b8b96970638e21b3f5ce8a58511f"
-}
diff --git a/.sqlx/query-bf1dfdea8293f1387da919b2b20163b8745840c55965712596892a1d8e3c62fe.json b/.sqlx/query-bf1dfdea8293f1387da919b2b20163b8745840c55965712596892a1d8e3c62fe.json
new file mode 100644
index 0000000000..30962b4898
--- /dev/null
+++ b/.sqlx/query-bf1dfdea8293f1387da919b2b20163b8745840c55965712596892a1d8e3c62fe.json
@@ -0,0 +1,153 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\", \n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL::text as \"model\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n d.\"updatedAt\"::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $5\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $6\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = d.id\n AND uh.\"itemType\" = 'document'\n AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n AND d.id = ANY($2::text[])\n AND EXISTS (\n SELECT 1 FROM entity_access ea\n WHERE ea.entity_id::text = d.id\n AND ea.entity_type = 'document'\n AND ea.source_id = ANY(ARRAY(SELECT source_id FROM user_source_ids))\n )\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n c.model as \"model\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n c.\"updatedAt\"::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id\n AND uh.\"itemType\" = 'chat'\n AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n AND c.id = ANY($3::text[])\n AND EXISTS (\n SELECT 1 FROM entity_access ea\n WHERE ea.entity_id::text = c.id\n AND ea.entity_type = 'chat'\n AND ea.source_id = ANY(ARRAY(SELECT source_id FROM user_source_ids))\n )\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL::text as \"model\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n p.\"updatedAt\"::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Project\" p\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id\n AND uh.\"itemType\" = 'project'\n AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n AND p.id = ANY($4::text[])\n AND EXISTS (\n SELECT 1 FROM entity_access ea\n WHERE ea.entity_id::text = p.id\n AND ea.entity_type = 'project'\n AND ea.source_id = ANY(ARRAY(SELECT source_id FROM user_source_ids))\n )\n )\n SELECT * \n FROM Combined\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 13,
+ "name": "model",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 15,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task",
+ "snippet",
+ "skill",
+ "initiative_description"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 16,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 17,
+ "name": "sort_ts!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 18,
+ "name": "is_completed",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 19,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "TextArray",
+ "TextArray",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "bf1dfdea8293f1387da919b2b20163b8745840c55965712596892a1d8e3c62fe"
+}
diff --git a/apps/web/src/lib/queries/soup/graphql/create-soup-live-query.ts b/apps/web/src/lib/queries/soup/graphql/create-soup-live-query.ts
index cd589bd5a6..406c900284 100644
--- a/apps/web/src/lib/queries/soup/graphql/create-soup-live-query.ts
+++ b/apps/web/src/lib/queries/soup/graphql/create-soup-live-query.ts
@@ -859,7 +859,13 @@ export function createSoupLiveQuery(
const initial =
'initial' in local.input ? local.input.initial : undefined;
const host = getGraphqlSoupCacheHost();
- if (!initial || !host || !isCachedMailView(initial.emailView)) return;
+ if (
+ !initial ||
+ !host ||
+ !isCachedMailView(initial.emailView) ||
+ initial.sortMethod === 'NOTIFIED_AT'
+ )
+ return;
const mailView = initial.emailView;
setFetchingMailPage(true);
try {
diff --git a/apps/web/src/lib/service-clients/service-storage/graphql/generated/graphql.ts b/apps/web/src/lib/service-clients/service-storage/graphql/generated/graphql.ts
index 68b8ef5055..2eb07964bb 100644
--- a/apps/web/src/lib/service-clients/service-storage/graphql/generated/graphql.ts
+++ b/apps/web/src/lib/service-clients/service-storage/graphql/generated/graphql.ts
@@ -1607,10 +1607,15 @@ export type GraphqlSharedEmailFilter =
/** The only option. */
| 'ONLY';
-/** GraphQL representation of supported simple Soup sorts. */
+/** GraphQL representation of supported Soup sorts. */
export type GraphqlSimpleSortMethod =
/** Sort by creation timestamp. */
| 'CREATED_AT'
+ /**
+ * Only entities the caller holds a live notification for, most recently
+ * notified first. Descending `soup` only; not supported by `groupSoup`.
+ */
+ | 'NOTIFIED_AT'
/** Sort by update timestamp. */
| 'UPDATED_AT'
/** Sort by most recently viewed. */
diff --git a/crates/graphql_soup/AGENTS.md b/crates/graphql_soup/AGENTS.md
index e1e896f768..ee1279ae15 100644
--- a/crates/graphql_soup/AGENTS.md
+++ b/crates/graphql_soup/AGENTS.md
@@ -16,3 +16,6 @@ viewer pattern), which apply to every type defined here.
serves lists. A thread shared through a team's CRM, a project, or a share
therefore opens through `emailThread` even though it lives in a teammate's
inbox.
+- `NOTIFIED_AT` maps to Soup's notified request, not a simple sort: `soup`
+ accepts it descending only and `groupSoup` rejects it. Its continuation
+ cursors carry a different sort tag, so `inputs.rs` decodes both cursor shapes.
diff --git a/crates/graphql_soup/src/inputs.rs b/crates/graphql_soup/src/inputs.rs
index 264d76a770..4b5257bc24 100644
--- a/crates/graphql_soup/src/inputs.rs
+++ b/crates/graphql_soup/src/inputs.rs
@@ -4,7 +4,7 @@ use graphql_soup_filter_input::GraphqlEntityFilterAst;
use item_filters::ast::{EntityFilterAst, properties::PropertyEntityType};
use macro_user_id::user_id::MacroUserIdStr;
use models_grouping::{GroupByField, GroupingConfig};
-use models_pagination::{Base64Str, CursorWithValAndFilter, Query, SimpleSortMethod};
+use models_pagination::{Base64Str, CursorWithValAndFilter, NotifiedAt, Query, SimpleSortMethod};
use soup::domain::models::{
GroupedSortRequest, SoupQuery, SoupRequest, SoupSortDirection, SoupType,
};
@@ -132,6 +132,7 @@ impl GroupedSoupInitialInput {
let sort_method = self
.sort_method
.map(GraphqlSimpleSortMethod::into_model)
+ .transpose()?
.unwrap_or(SimpleSortMethod::ViewedUpdated);
let limit = self.limit.unwrap_or(20).min(500);
@@ -274,16 +275,19 @@ impl SoupInitialInput {
.map(GraphqlEntityFilterAst::into_ast)
.transpose()?
.unwrap_or_default();
- let sort = self
+ let cursor = match self
.sort_method
- .map(GraphqlSimpleSortMethod::into_model)
- .unwrap_or(SimpleSortMethod::ViewedAt);
+ .unwrap_or(GraphqlSimpleSortMethod::ViewedAt)
+ {
+ GraphqlSimpleSortMethod::NotifiedAt => SoupQuery::new_sort_notified(filter),
+ sort => SoupQuery::new_sort_simple(sort.into_model()?, filter),
+ };
Ok(SoupRequest {
soup_type: soup_type(self.expand),
limit: self.limit.unwrap_or(20).min(500),
- cursor: SoupQuery::new_sort_simple(sort, filter),
- sort_direction: sort_direction(self.sort_direction),
+ sort_direction: sort_direction(&cursor, self.sort_direction)?,
+ cursor,
user: macro_user_id,
email_preview_view: email_preview_view(self.email_view)?,
link_ids,
@@ -298,18 +302,29 @@ impl SoupContinuationInput {
macro_user_id: MacroUserIdStr<'static>,
link_ids: Vec<Uuid>,
) -> async_graphql::Result<SoupRequest<EntityFilterAst>> {
- let cursor = Base64Str::<
- CursorWithValAndFilter<Uuid, SimpleSortMethod, EntityFilterAst>,
- >::new_from_string(self.cursor)
- .decode_json()
- .map_err(|err| async_graphql::Error::new(format!("invalid cursor: {err}")))?;
- let limit = u16::try_from(cursor.limit).unwrap_or(500).min(500);
+ // The sort tags never overlap, so at most one of these decodes.
+ let notified = Base64Str::<
+ CursorWithValAndFilter<String, NotifiedAt, EntityFilterAst>,
+ >::new_from_string(self.cursor.clone())
+ .decode_json();
+ let (limit, cursor) = match notified {
+ Ok(cursor) => (cursor.limit, SoupQuery::new_cursor_notified(cursor)),
+ Err(_) => {
+ let cursor = Base64Str::<
+ CursorWithValAndFilter<Uuid, SimpleSortMethod, EntityFilterAst>,
+ >::new_from_string(self.cursor)
+ .decode_json()
+ .map_err(|err| async_graphql::Error::new(format!("invalid cursor: {err}")))?;
+ (cursor.limit, SoupQuery::new_cursor_simple(cursor))
+ }
+ };
+ let limit = u16::try_from(limit).unwrap_or(500).min(500);
Ok(SoupRequest {
soup_type: soup_type(self.expand),
limit,
- cursor: SoupQuery::new_cursor_simple(cursor),
- sort_direction: sort_direction(self.sort_direction),
+ sort_direction: sort_direction(&cursor, self.sort_direction)?,
+ cursor,
user: macro_user_id,
email_preview_view: email_preview_view(self.email_view)?,
link_ids,
@@ -318,10 +333,21 @@ impl SoupContinuationInput {
}
/// Convert the optional GraphQL sort direction into the domain representation.
-fn sort_direction(direction: Option<GraphqlSortDirection>) -> SoupSortDirection {
- direction
+/// Notified pages are keyset-ordered newest first, so ascending is rejected
+/// rather than silently ignored.
+fn sort_direction(
+ cursor: &SoupQuery<EntityFilterAst>,
+ direction: Option<GraphqlSortDirection>,
+) -> async_graphql::Result<SoupSortDirection> {
+ let direction = direction
.map(GraphqlSortDirection::into_model)
- .unwrap_or_default()
+ .unwrap_or_default();
+ if direction == SoupSortDirection::Asc && matches!(cursor, SoupQuery::Notified(_)) {
+ return Err(async_graphql::Error::new(
+ "sortDirection ASC is not supported with NOTIFIED_AT",
+ ));
+ }
+ Ok(direction)
}
/// Convert the optional GraphQL expansion flag into the domain representation.
@@ -380,7 +406,7 @@ impl GraphqlEmailView {
// Filter input types and their authoritative materialization live in
// `graphql_soup_filter_input`, shared with the browser cache composition root.
-/// GraphQL representation of supported simple Soup sorts.
+/// GraphQL representation of supported Soup sorts.
#[derive(Enum, Copy, Clone, Eq, PartialEq)]
pub enum GraphqlSimpleSortMethod {
/// Sort by most recently viewed.
@@ -391,16 +417,23 @@ pub enum GraphqlSimpleSortMethod {
UpdatedAt,
/// Sort by viewed timestamp, falling back to updated timestamp.
ViewedUpdated,
+ /// Only entities the caller holds a live notification for, most recently
+ /// notified first. Descending `soup` only; not supported by `groupSoup`.
+ NotifiedAt,
}
impl GraphqlSimpleSortMethod {
- /// Convert this GraphQL sort method into the Soup-domain model.
- pub fn into_model(self) -> SimpleSortMethod {
+ /// Convert this GraphQL sort method into a timestamp sort, rejecting
+ /// `NOTIFIED_AT`, which is not one.
+ pub fn into_model(self) -> async_graphql::Result<SimpleSortMethod> {
match self {
- Self::ViewedAt => SimpleSortMethod::ViewedAt,
- Self::CreatedAt => SimpleSortMethod::CreatedAt,
- Self::UpdatedAt => SimpleSortMethod::UpdatedAt,
- Self::ViewedUpdated => SimpleSortMethod::ViewedUpdated,
+ Self::ViewedAt => Ok(SimpleSortMethod::ViewedAt),
+ Self::CreatedAt => Ok(SimpleSortMethod::CreatedAt),
+ Self::UpdatedAt => Ok(SimpleSortMethod::UpdatedAt),
+ Self::ViewedUpdated => Ok(SimpleSortMethod::ViewedUpdated),
+ Self::NotifiedAt => Err(async_graphql::Error::new(
+ "NOTIFIED_AT is only supported by soup",
+ )),
}
}
}
diff --git a/crates/graphql_soup/src/inputs/tests.rs b/crates/graphql_soup/src/inputs/tests.rs
index eae4175d22..17f5d168a0 100644
--- a/crates/graphql_soup/src/inputs/tests.rs
+++ b/crates/graphql_soup/src/inputs/tests.rs
@@ -67,6 +67,79 @@ fn maps_soup_cursor_continuation() {
assert!(matches!(request.soup_type, SoupType::UnExpanded));
}
+#[test]
+fn maps_notified_at_to_notified_soup_request() {
+ let request = SoupInput::Initial(Box::new(SoupInitialInput {
+ limit: Some(500),
+ expand: None,
+ sort_method: Some(GraphqlSimpleSortMethod::NotifiedAt),
+ email_view: None,
+ filters: None,
+ sort_direction: None,
+ }))
+ .into_request(test_macro_user_id(), vec![])
+ .unwrap();
+
+ assert_eq!(request.limit, 500);
+ assert!(matches!(request.cursor, SoupQuery::Notified(_)));
+}
+
+#[test]
+fn continues_a_notified_cursor_as_a_notified_request() {
+ let cursor = Base64Str::encode_json(CursorWithValAndFilter {
+ id: "00000000-0000-0000-0000-000000000001".to_owned(),
+ limit: 500,
+ val: CursorVal {
+ sort_type: NotifiedAt,
+ last_val: chrono::DateTime::default(),
+ },
+ filter: item_filters::ast::EntityFilterAst::default(),
+ });
+ let request = SoupInput::Continuation(SoupContinuationInput {
+ cursor: cursor.to_string(),
+ expand: None,
+ email_view: None,
+ sort_direction: None,
+ })
+ .into_request(test_macro_user_id(), vec![])
+ .unwrap();
+
+ assert_eq!(request.limit, 500);
+ assert!(matches!(request.cursor, SoupQuery::Notified(_)));
+}
+
+#[test]
+fn rejects_ascending_notified_at() {
+ let result = SoupInput::Initial(Box::new(SoupInitialInput {
+ limit: None,
+ expand: None,
+ sort_method: Some(GraphqlSimpleSortMethod::NotifiedAt),
+ email_view: None,
+ filters: None,
+ sort_direction: Some(GraphqlSortDirection::Asc),
+ }))
+ .into_request(test_macro_user_id(), vec![]);
+
+ assert!(result.is_err());
+}
+
+#[test]
+fn rejects_grouped_notified_at() {
+ let result = GroupedSoupInput::Initial(Box::new(GroupedSoupInitialInput {
+ group_by: GraphqlGroupByInput {
+ field: GraphqlGroupByField::EntityType,
+ property_definition_id: None,
+ entity_type: None,
+ },
+ limit: None,
+ sort_method: Some(GraphqlSimpleSortMethod::NotifiedAt),
+ filters: None,
+ }))
+ .into_request(test_macro_user_id());
+
+ assert!(result.is_err());
+}
+
#[test]
fn maps_initial_grouped_input() {
let request = GroupedSoupInput::Initial(Box::new(GroupedSoupInitialInput {
diff --git a/crates/soup/AGENTS.md b/crates/soup/AGENTS.md
index 8c0ab2c2b3..bc8757b37d 100644
--- a/crates/soup/AGENTS.md
+++ b/crates/soup/AGENTS.md
@@ -56,7 +56,8 @@ rows, initiatives, ...) and get back a single unified, paginated result.
## Checks
-- `cargo test -p soup` (`SQLX_OFFLINE` unset; needs local MacroDB).
+- `cargo test -p soup --features outbound` (`SQLX_OFFLINE` unset; needs local
+ MacroDB). Without the feature the Postgres repo and its tests don't compile.
- After schema/query changes: `nix develop --command just prepare_db` (see `justfile`).
## Gotchas
@@ -66,6 +67,11 @@ rows, initiatives, ...) and get back a single unified, paginated result.
`expanded` path instead.
- `candidate_gates.rs` encodes access-gate SQL shared across repo queries;
changing it changes what every entity kind can return.
+- Queries over a known id list (`*/by_ids.rs`, hydration) check access per id
+ with `EXISTS` on `entity_access`, matching sources with
+ `= ANY(ARRAY(SELECT ...))` so they are collected once rather than semi-joined
+ per row. Building the caller's whole accessible set first scans all of
+ `entity_access`, so cost grows with the table, not the page.
## Related
diff --git a/crates/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs b/crates/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
index 7038c15617..dfb2b3628e 100644
--- a/crates/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
+++ b/crates/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
@@ -54,13 +54,6 @@ async fn expanded_soup_by_ids_hydrated<'a>(
UNION ALL
SELECT $1
),
- UserAccessibleItems AS (
- SELECT DISTINCT
- ea.entity_id::text as item_id,
- ea.entity_type as item_type
- FROM entity_access ea
- WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
- ),
Combined AS (
SELECT
'document' as "item_type!",
@@ -124,9 +117,6 @@ async fn expanded_soup_by_ids_hydrated<'a>(
AND ep_status.entity_id = d.id
AND ep_status.entity_type = 'TASK'
AND ep_status.property_definition_id = $5
- INNER JOIN UserAccessibleItems uai
- ON uai.item_id = d.id
- AND uai.item_type = 'document'
LEFT JOIN "UserHistory" uh
ON uh."itemId" = d.id
AND uh."itemType" = 'document'
@@ -147,6 +137,12 @@ async fn expanded_soup_by_ids_hydrated<'a>(
) di ON true
WHERE d."deletedAt" IS NULL
AND d.id = ANY($2::text[])
+ AND EXISTS (
+ SELECT 1 FROM entity_access ea
+ WHERE ea.entity_id::text = d.id
+ AND ea.entity_type = 'document'
+ AND ea.source_id = ANY(ARRAY(SELECT source_id FROM user_source_ids))
+ )
UNION ALL
@@ -174,15 +170,18 @@ async fn expanded_soup_by_ids_hydrated<'a>(
NULL as "is_completed",
c."deletedAt"::timestamptz as "deleted_at"
FROM "Chat" c
- INNER JOIN UserAccessibleItems uai
- ON uai.item_id = c.id
- AND uai.item_type = 'chat'
LEFT JOIN "UserHistory" uh
ON uh."itemId" = c.id
AND uh."itemType" = 'chat'
AND uh."userId" = $1
WHERE c."deletedAt" IS NULL
AND c.id = ANY($3::text[])
+ AND EXISTS (
+ SELECT 1 FROM entity_access ea
+ WHERE ea.entity_id::text = c.id
+ AND ea.entity_type = 'chat'
+ AND ea.source_id = ANY(ARRAY(SELECT source_id FROM user_source_ids))
+ )
)
SELECT *
FROM Combined
diff --git a/crates/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs b/crates/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs
index 7ed4c12f41..35368ae467 100644
--- a/crates/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs
+++ b/crates/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs
@@ -50,13 +50,6 @@ pub async fn unexpanded_soup_by_ids<'a>(
UNION ALL
SELECT $1
),
- UserAccessibleItems AS (
- SELECT DISTINCT
- ea.entity_id::text as item_id,
- ea.entity_type as item_type
- FROM entity_access ea
- WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
- ),
Combined AS (
SELECT
'document' as "item_type!",
@@ -93,9 +86,6 @@ pub async fn unexpanded_soup_by_ids<'a>(
AND ep_status.entity_id = d.id
AND ep_status.entity_type = 'TASK'
AND ep_status.property_definition_id = $6
- INNER JOIN UserAccessibleItems uai
- ON uai.item_id = d.id
- AND uai.item_type = 'document'
LEFT JOIN "UserHistory" uh
ON uh."itemId" = d.id
AND uh."itemType" = 'document'
@@ -116,6 +106,12 @@ pub async fn unexpanded_soup_by_ids<'a>(
) di ON true
WHERE d."deletedAt" IS NULL
AND d.id = ANY($2::text[])
+ AND EXISTS (
+ SELECT 1 FROM entity_access ea
+ WHERE ea.entity_id::text = d.id
+ AND ea.entity_type = 'document'
+ AND ea.source_id = ANY(ARRAY(SELECT source_id FROM user_source_ids))
+ )
UNION ALL
@@ -141,15 +137,18 @@ pub async fn unexpanded_soup_by_ids<'a>(
NULL as "is_completed",
c."deletedAt"::timestamptz as "deleted_at"
FROM "Chat" c
- INNER JOIN UserAccessibleItems uai
- ON uai.item_id = c.id
- AND uai.item_type = 'chat'
LEFT JOIN "UserHistory" uh
ON uh."itemId" = c.id
AND uh."itemType" = 'chat'
AND uh."userId" = $1
WHERE c."deletedAt" IS NULL
AND c.id = ANY($3::text[])
+ AND EXISTS (
+ SELECT 1 FROM entity_access ea
+ WHERE ea.entity_id::text = c.id
+ AND ea.entity_type = 'chat'
+ AND ea.source_id = ANY(ARRAY(SELECT source_id FROM user_source_ids))
+ )
UNION ALL
@@ -175,15 +174,18 @@ pub async fn unexpanded_soup_by_ids<'a>(
NULL as "is_completed",
p."deletedAt"::timestamptz as "deleted_at"
FROM "Project" p
- INNER JOIN UserAccessibleItems uai
- ON uai.item_id = p.id
- AND uai.item_type = 'project'
LEFT JOIN "UserHistory" uh
ON uh."itemId" = p.id
AND uh."itemType" = 'project'
AND uh."userId" = $1
WHERE p."deletedAt" IS NULL
AND p.id = ANY($4::text[])
+ AND EXISTS (
+ SELECT 1 FROM entity_access ea
+ WHERE ea.entity_id::text = p.id
+ AND ea.entity_type = 'project'
+ AND ea.source_id = ANY(ARRAY(SELECT source_id FROM user_source_ids))
+ )
)
SELECT *
FROM Combined
diff --git a/static_assets/schema.graphql b/static_assets/schema.graphql
index a23e77a08c..b39ed885cc 100644
--- a/static_assets/schema.graphql
+++ b/static_assets/schema.graphql
@@ -6528,7 +6528,7 @@ enum GraphqlSharedEmailFilter {
}
"""
-GraphQL representation of supported simple Soup sorts.
+GraphQL representation of supported Soup sorts.
"""
enum GraphqlSimpleSortMethod {
"""
@@ -6547,6 +6547,11 @@ enum GraphqlSimpleSortMethod {
Sort by viewed timestamp, falling back to updated timestamp.
"""
VIEWED_UPDATED
+ """
+ Only entities the caller holds a live notification for, most recently
+ notified first. Descending `soup` only; not supported by `groupSoup`.
+ """
+ NOTIFIED_AT
}
"""