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.

fix(soup): Improve query performance (#1362)

Evan Hutnikb31480bd0d59
diff --git a/rust/cloud-storage/comms/justfile b/rust/cloud-storage/comms/justfile
new file mode 100644
index 0000000000..d5a52bc432
--- /dev/null
+++ b/rust/cloud-storage/comms/justfile
@@ -0,0 +1,6 @@
+DATABASE_URL := "postgres://user:password@localhost:5432/macrodb"
+
+mod sqlx '../sqlx.just'
+
+prepare_db:
+ just sqlx::prepare_db {{ DATABASE_URL }}
diff --git a/rust/cloud-storage/comms/src/outbound/http/user_repo.rs b/rust/cloud-storage/comms/src/outbound/http/user_repo.rs
index 5351e4ce38..cd1b256476 100644
--- a/rust/cloud-storage/comms/src/outbound/http/user_repo.rs
+++ b/rust/cloud-storage/comms/src/outbound/http/user_repo.rs
@@ -41,6 +41,7 @@ pub struct UserNames {
}
impl UserRepo for UserRepoImpl {
+ #[tracing::instrument(err, skip(self, user_ids))]
async fn get_names_for_ids(
&self,
user_ids: std::collections::HashSet<macro_user_id::user_id::MacroUserIdStr<'_>>,
diff --git a/rust/cloud-storage/document_storage_service/justfile b/rust/cloud-storage/document_storage_service/justfile
index e258eb06a4..8663436991 100644
--- a/rust/cloud-storage/document_storage_service/justfile
+++ b/rust/cloud-storage/document_storage_service/justfile
@@ -8,7 +8,7 @@ mod ensure '../ensure.just'
mod ci '../ci.just'
deploy-dev:
- just ci::deploy-dev document-storage
+ just ci::deploy-dev document-storage-service
run: ensure::ensure_dynamodb
cargo run -F local
diff --git a/rust/cloud-storage/email/src/domain/service.rs b/rust/cloud-storage/email/src/domain/service.rs
index f2a1fd2108..6eb6547458 100644
--- a/rust/cloud-storage/email/src/domain/service.rs
+++ b/rust/cloud-storage/email/src/domain/service.rs
@@ -39,6 +39,7 @@ where
U: FrecencyQueryService,
anyhow::Error: From<T::Err>,
{
+ #[tracing::instrument(err, skip(self, req))]
async fn get_email_thread_previews(
&self,
req: GetEmailsRequest,
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo.rs
index c6c8721911..6ddd9e2876 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo.rs
@@ -110,7 +110,7 @@ impl EmailRepo for EmailPgRepo {
.collect())
}
- #[tracing::instrument(err, skip(self))]
+ #[tracing::instrument(err, skip(self, thread_ids))]
async fn attachments_by_thread_ids(
&self,
thread_ids: &[Uuid],
@@ -148,7 +148,7 @@ impl EmailRepo for EmailPgRepo {
.collect())
}
- #[tracing::instrument(err, skip(self))]
+ #[tracing::instrument(err, skip(self, thread_ids))]
async fn contacts_by_thread_ids(&self, thread_ids: &[Uuid]) -> Result<Vec<Contact>, Self::Err> {
// Define a struct to hold the joined results
#[derive(Debug, Doppleganger)]
@@ -182,7 +182,7 @@ impl EmailRepo for EmailPgRepo {
.collect())
}
- #[tracing::instrument(err, skip(self))]
+ #[tracing::instrument(err, skip(self, thread_ids))]
async fn labels_by_thread_ids(&self, thread_ids: &[Uuid]) -> Result<Vec<Label>, Self::Err> {
// Query all labels for email_messages in the provided threads
// Include thread_id in the result set
diff --git a/rust/cloud-storage/frecency/src/domain/services.rs b/rust/cloud-storage/frecency/src/domain/services.rs
index 183d93331c..69d2becc3a 100644
--- a/rust/cloud-storage/frecency/src/domain/services.rs
+++ b/rust/cloud-storage/frecency/src/domain/services.rs
@@ -235,6 +235,7 @@ where
T: AggregateFrecencyStorage,
anyhow::Error: From<T::Err>,
{
+ #[tracing::instrument(err, skip(self, query))]
async fn get_frecency_page(
&self,
query: FrecencyPageRequest<'_>,
@@ -247,6 +248,7 @@ where
Ok(FrecencyPageResponse::new(res))
}
+ #[tracing::instrument(err, skip(self, request))]
async fn get_frecencies_by_ids<'a>(
&self,
request: FrecencyByIdsRequest<'a>,
diff --git a/rust/cloud-storage/frecency/src/outbound/postgres.rs b/rust/cloud-storage/frecency/src/outbound/postgres.rs
index 56e6a2e0f8..216446fa46 100644
--- a/rust/cloud-storage/frecency/src/outbound/postgres.rs
+++ b/rust/cloud-storage/frecency/src/outbound/postgres.rs
@@ -51,6 +51,7 @@ impl FrecencyPgStorage {
FrecencyPgStorage { pool }
}
+ #[tracing::instrument(err, skip(self))]
async fn static_get_top_entities(
&self,
user_id: MacroUserIdStr<'_>,
@@ -88,6 +89,7 @@ impl FrecencyPgStorage {
.collect()
}
+ #[tracing::instrument(err, skip(self, filter))]
async fn dynamic_get_top_entities(
&self,
user_id: MacroUserIdStr<'_>,
@@ -244,6 +246,7 @@ impl AggregateRow {
impl AggregateFrecencyStorage for FrecencyPgStorage {
type Err = FrecencyStorageErr;
+ #[tracing::instrument(err, skip(self, req))]
async fn get_top_entities(
&self,
req: FrecencyPageRequest<'_>,
@@ -307,6 +310,7 @@ impl AggregateFrecencyStorage for FrecencyPgStorage {
Ok(())
}
+ #[tracing::instrument(err, skip(self, entities))]
async fn get_aggregate_for_user_entities<'a>(
&self,
user_id: MacroUserIdStr<'a>,
diff --git a/rust/cloud-storage/frecency/src/outbound/postgres/dynamic.rs b/rust/cloud-storage/frecency/src/outbound/postgres/dynamic.rs
index 62ef4cf5cb..1fa16db816 100644
--- a/rust/cloud-storage/frecency/src/outbound/postgres/dynamic.rs
+++ b/rust/cloud-storage/frecency/src/outbound/postgres/dynamic.rs
@@ -246,6 +246,7 @@ impl AggregateRow {
}
}
+#[tracing::instrument(err, skip(db, filter))]
pub async fn dynamic_get_top_entities(
db: &PgPool,
user_id: MacroUserIdStr<'_>,
diff --git a/rust/cloud-storage/macro_db_client/fixtures/expanded_cursor_soup_exhaustive.sql b/rust/cloud-storage/macro_db_client/fixtures/expanded_cursor_soup_exhaustive.sql
new file mode 100644
index 0000000000..eddb4155f6
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/fixtures/expanded_cursor_soup_exhaustive.sql
@@ -0,0 +1,216 @@
+-- Exhaustive fixture for expanded_generic_cursor_soup tests.
+--
+-- Covers:
+-- - 3-level deep project hierarchy (root -> mid -> deep)
+-- - Deleted items (doc + chat) that must be excluded
+-- - Task documents with completed/incomplete/no-status states
+-- - Isolated project with no access for user-1
+-- - Second user for access isolation testing
+-- - Standalone items (no project) with direct access
+-- - Distinct timestamps for createdAt, updatedAt, and UserHistory.updatedAt
+-- so all four sort methods (viewed_at, updated_at, created_at, viewed_updated)
+-- produce different orderings.
+--
+-- User-1 accessible items (11 total):
+-- Projects: project-root, project-mid, project-deep
+-- Documents: doc-in-root, doc-in-mid, doc-in-deep, doc-standalone,
+-- doc-task-completed, doc-task-incomplete, doc-task-no-status
+-- Chats: chat-in-root, chat-standalone
+--
+-- NOT accessible to user-1:
+-- doc-deleted (deletedAt set), chat-deleted (deletedAt set),
+-- doc-isolated, chat-isolated, project-isolated (no access)
+--
+-- User-2 accessible items (3 total):
+-- project-isolated, doc-isolated, chat-isolated
+
+SET session_replication_role = 'replica';
+
+---------------------------------
+-- BASE SETUP: USERS & ORG
+---------------------------------
+
+INSERT INTO public."Organization" ("id", "name", "status")
+VALUES (1, 'Test Organization', 'PILOT')
+ON CONFLICT DO NOTHING;
+
+INSERT INTO public."User" ("id", "email", "stripeCustomerId", "organizationId")
+VALUES ('macro|[email protected]', '[email protected]', 'stripe_id_1', 1),
+ ('macro|[email protected]', '[email protected]', 'stripe_id_2', 1)
+ON CONFLICT DO NOTHING;
+
+---------------------------------
+-- PROJECT HIERARCHY: root -> mid -> deep
+---------------------------------
+
+INSERT INTO public."Project" ("id", "name", "userId", "parentId", "createdAt", "updatedAt")
+VALUES
+ ('aa000001-ffff-ffff-ffff-ffffffffffff', 'Project Root', 'macro|[email protected]', NULL,
+ '2024-01-10 10:00:00', '2024-02-10 10:00:00'),
+ ('aa000002-ffff-ffff-ffff-ffffffffffff', 'Project Mid', 'macro|[email protected]', 'aa000001-ffff-ffff-ffff-ffffffffffff',
+ '2024-01-11 10:00:00', '2024-02-11 10:00:00'),
+ ('aa000003-ffff-ffff-ffff-ffffffffffff', 'Project Deep', 'macro|[email protected]', 'aa000002-ffff-ffff-ffff-ffffffffffff',
+ '2024-01-12 10:00:00', '2024-02-12 10:00:00'),
+ -- Isolated project: user-1 has NO access, user-2 has owner
+ ('aa000004-ffff-ffff-ffff-ffffffffffff', 'Project Isolated', 'macro|[email protected]', NULL,
+ '2024-01-13 10:00:00', '2024-02-13 10:00:00');
+
+---------------------------------
+-- DOCUMENTS
+---------------------------------
+
+INSERT INTO public."DocumentFamily" ("id", "rootDocumentId")
+VALUES (101, 'bb000001-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+ (102, 'bb000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+ (103, 'bb000003-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+ (104, 'bb000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+ (105, 'bb000005-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+ (106, 'bb000006-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+ (107, 'bb000007-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+ (108, 'bb000008-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+ (109, 'bb000009-aaaa-aaaa-aaaa-aaaaaaaaaaaa');
+
+INSERT INTO public."Document" ("id", "name", "owner", "projectId", "documentFamilyId", "fileType", "createdAt", "updatedAt", "deletedAt")
+VALUES
+ -- Normal documents in hierarchy
+ ('bb000001-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Doc In Root', 'macro|[email protected]',
+ 'aa000001-ffff-ffff-ffff-ffffffffffff', 101, 'pdf',
+ '2024-01-01 10:00:00', '2024-02-01 10:00:00', NULL),
+ ('bb000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Doc In Mid', 'macro|[email protected]',
+ 'aa000002-ffff-ffff-ffff-ffffffffffff', 102, 'docx',
+ '2024-01-02 10:00:00', '2024-02-02 10:00:00', NULL),
+ ('bb000003-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Doc In Deep', 'macro|[email protected]',
+ 'aa000003-ffff-ffff-ffff-ffffffffffff', 103, 'pdf',
+ '2024-01-03 10:00:00', '2024-03-10 10:00:00', NULL),
+ -- Standalone document (no project, direct access)
+ ('bb000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Doc Standalone', 'macro|[email protected]',
+ NULL, 104, 'txt',
+ '2024-01-04 10:00:00', '2024-02-04 10:00:00', NULL),
+ -- Deleted document (should be excluded)
+ ('bb000005-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Doc Deleted', 'macro|[email protected]',
+ 'aa000001-ffff-ffff-ffff-ffffffffffff', 105, 'pdf',
+ '2024-01-15 10:00:00', '2024-02-15 10:00:00', '2024-03-01 10:00:00'),
+ -- Task documents for is_completed testing
+ ('bb000006-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Doc Task Completed', 'macro|[email protected]',
+ 'aa000001-ffff-ffff-ffff-ffffffffffff', 106, 'txt',
+ '2024-01-05 10:00:00', '2024-02-05 10:00:00', NULL),
+ ('bb000007-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Doc Task Incomplete', 'macro|[email protected]',
+ 'aa000001-ffff-ffff-ffff-ffffffffffff', 107, 'txt',
+ '2024-01-06 10:00:00', '2024-02-06 10:00:00', NULL),
+ ('bb000008-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Doc Task No Status', 'macro|[email protected]',
+ 'aa000001-ffff-ffff-ffff-ffffffffffff', 108, 'txt',
+ '2024-01-07 10:00:00', '2024-02-07 10:00:00', NULL),
+ -- Isolated document (in isolated project, user-1 has NO access)
+ ('bb000009-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Doc Isolated', 'macro|[email protected]',
+ 'aa000004-ffff-ffff-ffff-ffffffffffff', 109, 'pdf',
+ '2024-01-14 10:00:00', '2024-02-14 10:00:00', NULL);
+
+INSERT INTO public."DocumentInstance" ("documentId", "sha")
+VALUES ('bb000001-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-root'),
+ ('bb000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-mid'),
+ ('bb000003-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-deep'),
+ ('bb000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-standalone'),
+ ('bb000005-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-deleted'),
+ ('bb000006-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-task-completed'),
+ ('bb000007-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-task-incomplete'),
+ ('bb000008-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-task-no-status'),
+ ('bb000009-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-isolated');
+
+---------------------------------
+-- CHATS
+---------------------------------
+
+INSERT INTO public."Chat" ("id", "name", "userId", "projectId", "createdAt", "updatedAt", "deletedAt")
+VALUES
+ ('cc000001-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Chat In Root', 'macro|[email protected]',
+ 'aa000001-ffff-ffff-ffff-ffffffffffff',
+ '2024-01-08 10:00:00', '2024-02-08 10:00:00', NULL),
+ ('cc000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Chat Standalone', 'macro|[email protected]',
+ NULL,
+ '2024-01-09 10:00:00', '2024-03-11 10:00:00', NULL),
+ -- Deleted chat (should be excluded)
+ ('cc000003-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Chat Deleted', 'macro|[email protected]',
+ 'aa000001-ffff-ffff-ffff-ffffffffffff',
+ '2024-01-16 10:00:00', '2024-02-16 10:00:00', '2024-03-02 10:00:00'),
+ -- Isolated chat (in isolated project, user-1 has NO access)
+ ('cc000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Chat Isolated', 'macro|[email protected]',
+ 'aa000004-ffff-ffff-ffff-ffffffffffff',
+ '2024-01-17 10:00:00', '2024-02-17 10:00:00', NULL);
+
+---------------------------------
+-- TASK SUB-TYPES
+---------------------------------
+
+INSERT INTO public."document_sub_type" ("document_id", "sub_type")
+VALUES ('bb000006-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'task'),
+ ('bb000007-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'task'),
+ ('bb000008-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'task');
+
+-- Entity properties: Status for completed task
+-- Status property definition ID: '00000001-0000-0000-0000-000000000002'
+-- Completed status option ID: '00000001-0000-0000-0002-000000000004'
+INSERT INTO public."entity_properties" ("id", "entity_id", "entity_type", "property_definition_id", "values")
+VALUES
+ -- Completed task: Status = Completed
+ (gen_random_uuid(), 'bb000006-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'TASK',
+ '00000001-0000-0000-0000-000000000002',
+ '{"type": "SelectOption", "value": ["00000001-0000-0000-0002-000000000004"]}'::jsonb),
+ -- Incomplete task: Status = In Progress
+ (gen_random_uuid(), 'bb000007-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'TASK',
+ '00000001-0000-0000-0000-000000000002',
+ '{"type": "SelectOption", "value": ["00000001-0000-0000-0002-000000000002"]}'::jsonb);
+-- No entity_properties for doc-task-no-status (to test false case)
+
+---------------------------------
+-- USER ACCESS PERMISSIONS
+---------------------------------
+
+INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+VALUES
+ -- user-1: owner on project-root (inherits to mid and deep)
+ (gen_random_uuid(), 'macro|[email protected]', 'aa000001-ffff-ffff-ffff-ffffffffffff', 'project', 'owner'),
+ -- user-1: direct access to standalone items
+ (gen_random_uuid(), 'macro|[email protected]', 'bb000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', 'cc000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'owner'),
+ -- user-2: owner on isolated project
+ (gen_random_uuid(), 'macro|[email protected]', 'aa000004-ffff-ffff-ffff-ffffffffffff', 'project', 'owner');
+
+---------------------------------
+-- USER HISTORY
+-- Some items have history, some don't, to test viewed_at vs viewed_updated differences.
+-- Items WITHOUT history but with high updatedAt will rank differently
+-- under viewed_updated vs viewed_at sort.
+---------------------------------
+
+INSERT INTO public."UserHistory" ("userId", "itemId", "itemType", "createdAt", "updatedAt")
+VALUES
+ -- doc-in-root: viewed_at = 2024-03-05
+ ('macro|[email protected]', 'bb000001-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document',
+ '2024-01-01 00:00:00', '2024-03-05 10:00:00'),
+ -- doc-in-mid: viewed_at = 2024-03-08 (most recently viewed doc)
+ ('macro|[email protected]', 'bb000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document',
+ '2024-01-01 00:00:00', '2024-03-08 10:00:00'),
+ -- doc-in-deep: NO HISTORY (but updatedAt = 2024-03-10, very recent)
+ -- doc-standalone: viewed_at = 2024-03-06
+ ('macro|[email protected]', 'bb000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document',
+ '2024-01-01 00:00:00', '2024-03-06 10:00:00'),
+ -- doc-task-completed: viewed_at = 2024-03-04
+ ('macro|[email protected]', 'bb000006-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document',
+ '2024-01-01 00:00:00', '2024-03-04 10:00:00'),
+ -- doc-task-incomplete: NO HISTORY
+ -- doc-task-no-status: viewed_at = 2024-03-07
+ ('macro|[email protected]', 'bb000008-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document',
+ '2024-01-01 00:00:00', '2024-03-07 10:00:00'),
+ -- chat-in-root: viewed_at = 2024-03-03
+ ('macro|[email protected]', 'cc000001-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat',
+ '2024-01-01 00:00:00', '2024-03-03 10:00:00'),
+ -- chat-standalone: NO HISTORY (but updatedAt = 2024-03-11, highest)
+ -- project-root: viewed_at = 2024-03-02
+ ('macro|[email protected]', 'aa000001-ffff-ffff-ffff-ffffffffffff', 'project',
+ '2024-01-01 00:00:00', '2024-03-02 10:00:00'),
+ -- project-mid: NO HISTORY
+ -- project-deep: viewed_at = 2024-03-01
+ ('macro|[email protected]', 'aa000003-ffff-ffff-ffff-ffffffffffff', 'project',
+ '2024-01-01 00:00:00', '2024-03-01 10:00:00');
+
+SET session_replication_role = 'origin';
diff --git a/rust/cloud-storage/macro_db_client/fixtures/sorting_expanded_items.sql b/rust/cloud-storage/macro_db_client/fixtures/sorting_expanded_items.sql
index 107636d15b..0456a7045d 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/sorting_expanded_items.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/sorting_expanded_items.sql
@@ -6,7 +6,7 @@
-- Expected Order for CreatedAt: doc-B, chat-A, doc-A
-- Expected Order for UpdatedAt: chat-A, doc-A, doc-B
--- Expected Order for LastViewed: doc-A, doc-B, chat-A (chat-B is filtered out)
+-- Expected Order for LastViewed: doc-A, doc-B, chat-A, project-B, chat-B, project-A (epoch items tiebroken by id DESC)
SET session_replication_role = 'replica';
diff --git a/rust/cloud-storage/soup/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json b/rust/cloud-storage/soup/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json
deleted file mode 100644
index d2b084cf10..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n 'TASK'::property_entity_type,\n u.property_definition_id,\n u.values\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::UUID[],\n $4::JSONB[]\n ) AS u(id, entity_id, property_definition_id, values)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO UPDATE SET \n values = EXCLUDED.values,\n updated_at = NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "UuidArray",
- "JsonbArray"
- ]
- },
- "nullable": []
- },
- "hash": "1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-1b324f7419bf6620c5eae611b237ee202fb2b3b011422dc27f351a2c3d10813c.json b/rust/cloud-storage/soup/.sqlx/query-1b324f7419bf6620c5eae611b237ee202fb2b3b011422dc27f351a2c3d10813c.json
deleted file mode 100644
index 8257f56f38..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-1b324f7419bf6620c5eae611b237ee202fb2b3b011422dc27f351a2c3d10813c.json
+++ /dev/null
@@ -1,184 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\nSELECT\n ep.id as entity_property_id,\n ep.entity_id,\n ep.entity_type as \"entity_type: EntityType\",\n ep.property_definition_id,\n ep.values as \"values: sqlx::types::JsonValue\",\n ep.created_at as entity_property_created_at,\n ep.updated_at as entity_property_updated_at,\n pd.organization_id as definition_organization_id,\n pd.user_id as definition_user_id,\n pd.display_name,\n pd.data_type as \"data_type: DataType\",\n pd.is_multi_select,\n pd.specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n pd.created_at as definition_created_at,\n pd.updated_at as definition_updated_at,\n pd.is_system as definition_is_system\nFROM entity_properties ep\nINNER JOIN property_definitions pd ON ep.property_definition_id = pd.id\nWHERE (ep.entity_id, ep.entity_type) IN (\n SELECT * FROM UNNEST($1::TEXT[], $2::property_entity_type[])\n)\n",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "entity_property_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "entity_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "entity_type: EntityType",
- "type_info": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 3,
- "name": "property_definition_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 4,
- "name": "values: sqlx::types::JsonValue",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 5,
- "name": "entity_property_created_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 6,
- "name": "entity_property_updated_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "definition_organization_id",
- "type_info": "Int4"
- },
- {
- "ordinal": 8,
- "name": "definition_user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "display_name",
- "type_info": "Text"
- },
- {
- "ordinal": 10,
- "name": "data_type: DataType",
- "type_info": {
- "Custom": {
- "name": "property_data_type",
- "kind": {
- "Enum": [
- "BOOLEAN",
- "DATE",
- "NUMBER",
- "STRING",
- "SELECT_NUMBER",
- "SELECT_STRING",
- "ENTITY",
- "LINK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 11,
- "name": "is_multi_select",
- "type_info": "Bool"
- },
- {
- "ordinal": 12,
- "name": "specific_entity_type: Option<EntityType>",
- "type_info": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 13,
- "name": "definition_created_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 14,
- "name": "definition_updated_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 15,
- "name": "definition_is_system",
- "type_info": "Bool"
- }
- ],
- "parameters": {
- "Left": [
- "TextArray",
- {
- "Custom": {
- "name": "property_entity_type[]",
- "kind": {
- "Array": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- }
- }
- }
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- true,
- false,
- false,
- true,
- true,
- false,
- false,
- false,
- true,
- false,
- false,
- false
- ]
- },
- "hash": "1b324f7419bf6620c5eae611b237ee202fb2b3b011422dc27f351a2c3d10813c"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-63c1f6167cbc12ae74d080e0079e3394e70746aedb30a75958096f70ff526a08.json b/rust/cloud-storage/soup/.sqlx/query-31df7fdfa81e8a92373c62309b14486268a5a99e5371e7f08fab2716d7688192.json
similarity index 98%
rename from rust/cloud-storage/soup/.sqlx/query-63c1f6167cbc12ae74d080e0079e3394e70746aedb30a75958096f70ff526a08.json
rename to rust/cloud-storage/soup/.sqlx/query-31df7fdfa81e8a92373c62309b14486268a5a99e5371e7f08fab2716d7688192.json
index 6f51cc9f8a..5a9bcfe5b6 100644
--- a/rust/cloud-storage/soup/.sqlx/query-63c1f6167cbc12ae74d080e0079e3394e70746aedb30a75958096f70ff526a08.json
+++ b/rust/cloud-storage/soup/.sqlx/query-31df7fdfa81e8a92373c62309b14486268a5a99e5371e7f08fab2716d7688192.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": " \n WITH RECURSIVE ProjectHierarchy AS (\n SELECT p.id, uia.access_level \n FROM \"Project\" p\n JOIN \"UserItemAccess\" uia ON p.id = uia.item_id AND uia.item_type = 'project'\n WHERE uia.user_id = $1 AND p.\"deletedAt\" IS NULL\n UNION ALL\n SELECT p.id, ph.access_level\n FROM \"Project\" p \n JOIN ProjectHierarchy ph ON p.\"parentId\" = ph.id\n WHERE p.\"deletedAt\" IS NULL\n ),\n AllAccessGrants AS (\n SELECT item_id, item_type, access_level \n FROM \"UserItemAccess\" \n WHERE user_id = $1\n UNION ALL\n SELECT d.id AS item_id, 'document' AS item_type, ph.access_level\n FROM \"Document\" d \n JOIN ProjectHierarchy ph ON d.\"projectId\" = ph.id\n WHERE d.\"projectId\" IS NOT NULL AND d.\"deletedAt\" IS NULL\n UNION ALL\n SELECT c.id AS item_id, 'chat' AS item_type, ph.access_level\n FROM \"Chat\" c \n JOIN ProjectHierarchy ph ON c.\"projectId\" = ph.id\n WHERE c.\"projectId\" IS NOT NULL AND c.\"deletedAt\" IS NULL\n UNION ALL\n SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level \n FROM ProjectHierarchy ph\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT ON (item_id, item_type) item_id, item_type\n FROM AllAccessGrants\n ORDER BY item_id, item_type, \n CASE access_level\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3 \n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\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 di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\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 = $7\n INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'\n -- This MUST be a LEFT JOIN to support all three sort methods\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' 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\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 NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::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 ON uai.item_id = c.id AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\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 as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::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 )\n SELECT Combined.* FROM Combined\n LEFT JOIN frecency_aggregates fa\n ON fa.entity_id = Combined.\"id!\"\n AND fa.entity_type = Combined.\"item_type!\"\n AND fa.user_id = $1\n WHERE fa.id IS NULL\n AND (\n ($4::timestamptz IS NULL)\n OR\n (Combined.\"sort_ts!\", Combined.\"id!\"::text) < ($4, $5)\n )\n ORDER BY Combined.\"sort_ts!\" DESC, Combined.\"updated_at!\" DESC\n LIMIT $3\n ",
+ "query": " \n WITH RECURSIVE ProjectHierarchy AS (\n SELECT p.id, uia.access_level \n FROM \"Project\" p\n JOIN \"UserItemAccess\" uia ON p.id = uia.item_id AND uia.item_type = 'project'\n WHERE uia.user_id = $1 AND p.\"deletedAt\" IS NULL\n UNION ALL\n SELECT p.id, ph.access_level\n FROM \"Project\" p \n JOIN ProjectHierarchy ph ON p.\"parentId\" = ph.id\n WHERE p.\"deletedAt\" IS NULL\n ),\n AllAccessGrants AS (\n SELECT item_id, item_type, access_level \n FROM \"UserItemAccess\" \n WHERE user_id = $1\n UNION ALL\n SELECT d.id AS item_id, 'document' AS item_type, ph.access_level\n FROM \"Document\" d \n JOIN ProjectHierarchy ph ON d.\"projectId\" = ph.id\n WHERE d.\"projectId\" IS NOT NULL AND d.\"deletedAt\" IS NULL\n UNION ALL\n SELECT c.id AS item_id, 'chat' AS item_type, ph.access_level\n FROM \"Chat\" c \n JOIN ProjectHierarchy ph ON c.\"projectId\" = ph.id\n WHERE c.\"projectId\" IS NOT NULL AND c.\"deletedAt\" IS NULL\n UNION ALL\n SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level \n FROM ProjectHierarchy ph\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT ON (item_id, item_type) item_id, item_type\n FROM AllAccessGrants\n ORDER BY item_id, item_type, \n CASE access_level\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3 \n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\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 di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\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 = $7\n INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'\n -- This MUST be a LEFT JOIN to support all three sort methods\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' 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\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 NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::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 ON uai.item_id = c.id AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\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 as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::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 )\n SELECT Combined.* FROM Combined\n LEFT JOIN frecency_aggregates fa\n ON fa.entity_id = Combined.\"id!\"\n AND fa.entity_type = Combined.\"item_type!\"\n AND fa.user_id = $1\n WHERE fa.id IS NULL\n AND (\n ($4::timestamptz IS NULL)\n OR\n (Combined.\"sort_ts!\", Combined.\"id!\"::text) < ($4, $5)\n )\n ORDER BY Combined.\"sort_ts!\" DESC, Combined.\"id!\" DESC\n LIMIT $3\n ",
"describe": {
"columns": [
{
@@ -141,5 +141,5 @@
null
]
},
- "hash": "63c1f6167cbc12ae74d080e0079e3394e70746aedb30a75958096f70ff526a08"
+ "hash": "31df7fdfa81e8a92373c62309b14486268a5a99e5371e7f08fab2716d7688192"
}
diff --git a/rust/cloud-storage/soup/.sqlx/query-35aa1ada3371fd09902d19b1218c2034a348d30889a11f28b98a9e4a0daf4525.json b/rust/cloud-storage/soup/.sqlx/query-35aa1ada3371fd09902d19b1218c2034a348d30889a11f28b98a9e4a0daf4525.json
deleted file mode 100644
index 0bc29e54eb..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-35aa1ada3371fd09902d19b1218c2034a348d30889a11f28b98a9e4a0daf4525.json
+++ /dev/null
@@ -1,177 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\nSELECT\n ep.id as entity_property_id,\n ep.entity_id,\n ep.entity_type as \"entity_type: EntityType\",\n ep.property_definition_id,\n ep.values as \"values: sqlx::types::JsonValue\",\n ep.created_at as entity_property_created_at,\n ep.updated_at as entity_property_updated_at,\n pd.organization_id as definition_organization_id,\n pd.user_id as definition_user_id,\n pd.display_name,\n pd.data_type as \"data_type: DataType\",\n pd.is_multi_select,\n pd.specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n pd.created_at as definition_created_at,\n pd.updated_at as definition_updated_at,\n pd.is_system as definition_is_system\nFROM entity_properties ep\nINNER JOIN property_definitions pd ON ep.property_definition_id = pd.id\nWHERE ep.entity_id = $1 AND ep.entity_type = $2\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "entity_property_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "entity_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "entity_type: EntityType",
- "type_info": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 3,
- "name": "property_definition_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 4,
- "name": "values: sqlx::types::JsonValue",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 5,
- "name": "entity_property_created_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 6,
- "name": "entity_property_updated_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "definition_organization_id",
- "type_info": "Int4"
- },
- {
- "ordinal": 8,
- "name": "definition_user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "display_name",
- "type_info": "Text"
- },
- {
- "ordinal": 10,
- "name": "data_type: DataType",
- "type_info": {
- "Custom": {
- "name": "property_data_type",
- "kind": {
- "Enum": [
- "BOOLEAN",
- "DATE",
- "NUMBER",
- "STRING",
- "SELECT_NUMBER",
- "SELECT_STRING",
- "ENTITY",
- "LINK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 11,
- "name": "is_multi_select",
- "type_info": "Bool"
- },
- {
- "ordinal": 12,
- "name": "specific_entity_type: Option<EntityType>",
- "type_info": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 13,
- "name": "definition_created_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 14,
- "name": "definition_updated_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 15,
- "name": "definition_is_system",
- "type_info": "Bool"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- true,
- false,
- false,
- true,
- true,
- false,
- false,
- false,
- true,
- false,
- false,
- false
- ]
- },
- "hash": "35aa1ada3371fd09902d19b1218c2034a348d30889a11f28b98a9e4a0daf4525"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-3e259ea5cbdcfae4334cb0125de6423fa95a0c127fbeba0a59d7096b0177c072.json b/rust/cloud-storage/soup/.sqlx/query-3e259ea5cbdcfae4334cb0125de6423fa95a0c127fbeba0a59d7096b0177c072.json
deleted file mode 100644
index 8ee9d7919b..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-3e259ea5cbdcfae4334cb0125de6423fa95a0c127fbeba0a59d7096b0177c072.json
+++ /dev/null
@@ -1,52 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT\n p.id,\n p.name,\n p.\"userId\" as \"owner\",\n p.\"parentId\" as \"parent_id\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\"\n FROM\n \"Project\" p\n WHERE\n p.id = $1 AND p.\"deletedAt\" IS NULL\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "name",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "owner",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "parent_id",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 5,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- true,
- null,
- null
- ]
- },
- "hash": "3e259ea5cbdcfae4334cb0125de6423fa95a0c127fbeba0a59d7096b0177c072"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-3f3b5a5d8734e3748d4e29d64cfa89baff99dae621e7cbd7a10017beec9485c8.json b/rust/cloud-storage/soup/.sqlx/query-3f3b5a5d8734e3748d4e29d64cfa89baff99dae621e7cbd7a10017beec9485c8.json
deleted file mode 100644
index 5c152ecd5e..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-3f3b5a5d8734e3748d4e29d64cfa89baff99dae621e7cbd7a10017beec9485c8.json
+++ /dev/null
@@ -1,50 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\nSELECT\n ep.entity_id,\n ep.entity_type as \"entity_type: EntityType\",\n ep.property_definition_id\nFROM entity_properties ep\nWHERE ep.id = $1\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "entity_id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "entity_type: EntityType",
- "type_info": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 2,
- "name": "property_definition_id",
- "type_info": "Uuid"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid"
- ]
- },
- "nullable": [
- false,
- false,
- false
- ]
- },
- "hash": "3f3b5a5d8734e3748d4e29d64cfa89baff99dae621e7cbd7a10017beec9485c8"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-41682a8f6e1e2fb8836f76ca3ceab5fe676b45c9942ec0c99486c03e52733a47.json b/rust/cloud-storage/soup/.sqlx/query-41682a8f6e1e2fb8836f76ca3ceab5fe676b45c9942ec0c99486c03e52733a47.json
deleted file mode 100644
index 7eab7370d7..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-41682a8f6e1e2fb8836f76ca3ceab5fe676b45c9942ec0c99486c03e52733a47.json
+++ /dev/null
@@ -1,38 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO property_options (\n id,\n property_definition_id,\n display_order,\n number_value,\n string_value\n )\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id, created_at, updated_at\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "created_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 2,
- "name": "updated_at",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "Uuid",
- "Int4",
- "Float8",
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false
- ]
- },
- "hash": "41682a8f6e1e2fb8836f76ca3ceab5fe676b45c9942ec0c99486c03e52733a47"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-5fabf029c6dd06505963dab2b60eccb8ea77088f535970dbcf5f80d57a9a4c5b.json b/rust/cloud-storage/soup/.sqlx/query-5fabf029c6dd06505963dab2b60eccb8ea77088f535970dbcf5f80d57a9a4c5b.json
deleted file mode 100644
index c853ae04b7..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-5fabf029c6dd06505963dab2b60eccb8ea77088f535970dbcf5f80d57a9a4c5b.json
+++ /dev/null
@@ -1,110 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n id,\n organization_id,\n user_id,\n display_name,\n data_type as \"data_type: DataType\",\n is_multi_select,\n specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n created_at,\n updated_at,\n is_system\n FROM property_definitions\n WHERE id = $1\n AND is_system = FALSE\n AND (\n user_id = $2\n OR ($3::int IS NOT NULL AND organization_id = $3)\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "organization_id",
- "type_info": "Int4"
- },
- {
- "ordinal": 2,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "display_name",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "data_type: DataType",
- "type_info": {
- "Custom": {
- "name": "property_data_type",
- "kind": {
- "Enum": [
- "BOOLEAN",
- "DATE",
- "NUMBER",
- "STRING",
- "SELECT_NUMBER",
- "SELECT_STRING",
- "ENTITY",
- "LINK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 5,
- "name": "is_multi_select",
- "type_info": "Bool"
- },
- {
- "ordinal": 6,
- "name": "specific_entity_type: Option<EntityType>",
- "type_info": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 7,
- "name": "created_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 8,
- "name": "updated_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "is_system",
- "type_info": "Bool"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "Text",
- "Int4"
- ]
- },
- "nullable": [
- false,
- true,
- true,
- false,
- false,
- false,
- true,
- false,
- false,
- false
- ]
- },
- "hash": "5fabf029c6dd06505963dab2b60eccb8ea77088f535970dbcf5f80d57a9a4c5b"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json b/rust/cloud-storage/soup/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json
deleted file mode 100644
index 6d97183829..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n 'TASK'::property_entity_type,\n u.property_definition_id,\n NULL\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::UUID[]\n ) AS u(id, entity_id, property_definition_id)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO NOTHING\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "UuidArray"
- ]
- },
- "nullable": []
- },
- "hash": "63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-6abeabf893d033f575f7814b49d57ac0f37d2a2f012002d01453e698f120fd96.json b/rust/cloud-storage/soup/.sqlx/query-6abeabf893d033f575f7814b49d57ac0f37d2a2f012002d01453e698f120fd96.json
new file mode 100644
index 0000000000..88b3d044bb
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-6abeabf893d033f575f7814b49d57ac0f37d2a2f012002d01453e698f120fd96.json
@@ -0,0 +1,145 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n -- =============================================================================\n -- EXPANDED GENERIC CURSOR SOUP QUERY\n -- =============================================================================\n -- Retrieves all items (documents, chats, projects) that a user has access to,\n -- including both explicit permissions and inherited permissions through the\n -- project hierarchy.\n -- =============================================================================\n\n -- Build the project hierarchy tree using recursive CTE.\n -- Starting from projects the user has explicit access to, recursively find\n -- all child projects. This enables inherited access - if you can access a\n -- parent project, you can access all its descendants.\n WITH RECURSIVE ProjectHierarchy AS (\n -- Base case: projects the user has direct access to\n SELECT p.id, uia.access_level\n FROM \"Project\" p\n JOIN \"UserItemAccess\" uia ON p.id = uia.item_id AND uia.item_type = 'project'\n WHERE uia.user_id = $1 AND p.\"deletedAt\" IS NULL\n UNION ALL\n -- Recursive case: find child projects, inheriting parent's access level\n SELECT p.id, ph.access_level\n FROM \"Project\" p\n JOIN ProjectHierarchy ph ON p.\"parentId\" = ph.id\n WHERE p.\"deletedAt\" IS NULL\n ),\n\n -- Collect all access grants from multiple sources.\n -- Aggregates explicit permissions AND implicit permissions inherited\n -- through project membership.\n AllAccessGrants AS (\n -- Direct/explicit access grants to any item type\n SELECT item_id, item_type, access_level\n FROM \"UserItemAccess\"\n WHERE user_id = $1\n\n UNION ALL\n\n -- Documents within accessible projects (inherited access).\n -- Uses ANY(ARRAY(...)) pattern to reduce intermediate result set size.\n SELECT d.id AS item_id, 'document' AS item_type,\n (SELECT ph.access_level FROM ProjectHierarchy ph WHERE ph.id = d.\"projectId\" LIMIT 1) as access_level\n FROM \"Document\" d\n WHERE d.\"projectId\" = ANY(ARRAY(SELECT id FROM ProjectHierarchy))\n AND d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Chats within accessible projects (inherited access)\n SELECT c.id AS item_id, 'chat' AS item_type, ph.access_level\n FROM \"Chat\" c\n JOIN ProjectHierarchy ph ON c.\"projectId\" = ph.id\n WHERE c.\"projectId\" IS NOT NULL AND c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- The projects themselves from the hierarchy\n SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level\n FROM ProjectHierarchy ph\n ),\n\n -- Deduplicate access grants, keeping the highest permission level.\n -- When a user has multiple access paths to the same item (e.g., direct + inherited),\n -- we keep only one row with the highest privilege level.\n UserAccessibleItems AS (\n SELECT DISTINCT ON (item_id, item_type) item_id, item_type\n FROM AllAccessGrants\n ORDER BY item_id, item_type,\n -- Priority: owner > edit > comment > view\n CASE access_level\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3\n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\n ),\n\n -- Identify the top N items with minimal columns before joining full details.\n -- Performs early filtering and sorting to reduce the data processed in\n -- subsequent joins.\n TopItems AS (\n SELECT item_type, id, sort_ts, updated_at FROM (\n SELECT\n 'document'::text as item_type,\n d.id,\n -- Dynamic sort column based on user's selected sort method\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as sort_ts,\n d.\"updatedAt\"::timestamptz as updated_at\n FROM \"Document\" d\n INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n WHERE d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'chat'::text,\n c.id,\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::timestamptz,\n c.\"updatedAt\"::timestamptz\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai ON uai.item_id = c.id AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'project'::text,\n p.id,\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::timestamptz,\n p.\"updatedAt\"::timestamptz\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai ON uai.item_id = p.id AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = p.id AND uh.\"itemType\" = 'project' AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n ) all_items\n WHERE\n -- Cursor-based pagination: skip items we've already seen.\n -- NULL cursor means first page (no items to skip).\n ($4::timestamptz IS NULL)\n OR\n -- Seek method: find items \"before\" the cursor position\n -- using (sort_ts, id) tuple comparison for deterministic ordering\n (sort_ts, id::text) < ($4, $5)\n ORDER BY sort_ts DESC, id DESC\n LIMIT $3\n )\n\n -- Join full item details only for the filtered top items.\n SELECT * FROM (\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 di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n -- Task completion status: check if status property matches \"completed\"\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\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 TopItems t\n INNER JOIN \"Document\" d ON d.id = t.id\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 = $7\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n -- LATERAL joins to get the latest version info\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 t.item_type = 'document'\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 NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Chat\" c ON c.id = t.id\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE t.item_type = 'chat'\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 as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Project\" p ON p.id = t.id\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id AND uh.\"itemType\" = 'project' AND uh.\"userId\" = $1\n WHERE t.item_type = 'project'\n ) Combined\n -- Sort by timestamp descending, with ID as tiebreaker for deterministic pagination.\n -- This ensures consistent ordering when multiple items share the same timestamp,\n -- preventing items from being skipped or duplicated across pages.\n ORDER BY \"sort_ts!\" DESC, \"id!\" DESC\n LIMIT $3\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": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 15,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 16,
+ "name": "sort_ts!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 17,
+ "name": "is_completed",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 18,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Int8",
+ "Timestamptz",
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "6abeabf893d033f575f7814b49d57ac0f37d2a2f012002d01453e698f120fd96"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-732141210551d42218ce027266c6dfa3dd1f0ddb2c37493ed1235fe488073d89.json b/rust/cloud-storage/soup/.sqlx/query-732141210551d42218ce027266c6dfa3dd1f0ddb2c37493ed1235fe488073d89.json
deleted file mode 100644
index ea49b9c1cd..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-732141210551d42218ce027266c6dfa3dd1f0ddb2c37493ed1235fe488073d89.json
+++ /dev/null
@@ -1,108 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n id,\n organization_id,\n user_id,\n display_name,\n data_type as \"data_type: DataType\",\n is_multi_select,\n specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n created_at,\n updated_at,\n is_system\n FROM property_definitions\n WHERE id = $1\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "organization_id",
- "type_info": "Int4"
- },
- {
- "ordinal": 2,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "display_name",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "data_type: DataType",
- "type_info": {
- "Custom": {
- "name": "property_data_type",
- "kind": {
- "Enum": [
- "BOOLEAN",
- "DATE",
- "NUMBER",
- "STRING",
- "SELECT_NUMBER",
- "SELECT_STRING",
- "ENTITY",
- "LINK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 5,
- "name": "is_multi_select",
- "type_info": "Bool"
- },
- {
- "ordinal": 6,
- "name": "specific_entity_type: Option<EntityType>",
- "type_info": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 7,
- "name": "created_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 8,
- "name": "updated_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "is_system",
- "type_info": "Bool"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid"
- ]
- },
- "nullable": [
- false,
- true,
- true,
- false,
- false,
- false,
- true,
- false,
- false,
- false
- ]
- },
- "hash": "732141210551d42218ce027266c6dfa3dd1f0ddb2c37493ed1235fe488073d89"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-7ae5368ee01e670dcc9804096f3d3e9dcab6dcebcb601bfb1ed190dbda0ff37f.json b/rust/cloud-storage/soup/.sqlx/query-7ae5368ee01e670dcc9804096f3d3e9dcab6dcebcb601bfb1ed190dbda0ff37f.json
deleted file mode 100644
index a33e79f60e..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-7ae5368ee01e670dcc9804096f3d3e9dcab6dcebcb601bfb1ed190dbda0ff37f.json
+++ /dev/null
@@ -1,34 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n VALUES ($1, $2, $3, $4, $5)\n ON CONFLICT (entity_id, entity_type, property_definition_id) \n DO UPDATE SET \n values = EXCLUDED.values,\n updated_at = NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid",
- "Text",
- {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- },
- "Uuid",
- "Jsonb"
- ]
- },
- "nullable": []
- },
- "hash": "7ae5368ee01e670dcc9804096f3d3e9dcab6dcebcb601bfb1ed190dbda0ff37f"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-827b998f442f5f6cb6ff85dc35f01c5782128a4cb9a020e22ab83a24a6c2b4f5.json b/rust/cloud-storage/soup/.sqlx/query-827b998f442f5f6cb6ff85dc35f01c5782128a4cb9a020e22ab83a24a6c2b4f5.json
deleted file mode 100644
index d172804854..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-827b998f442f5f6cb6ff85dc35f01c5782128a4cb9a020e22ab83a24a6c2b4f5.json
+++ /dev/null
@@ -1,110 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n id,\n organization_id,\n user_id,\n display_name,\n data_type as \"data_type: DataType\",\n is_multi_select,\n specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n created_at,\n updated_at,\n is_system\n FROM property_definitions\n WHERE \n ($3 AND is_system)\n OR (\n ($1::int IS NOT NULL AND organization_id = $1) \n OR ($2::text IS NOT NULL AND user_id = $2)\n )\n ORDER BY LOWER(display_name) ASC\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "organization_id",
- "type_info": "Int4"
- },
- {
- "ordinal": 2,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "display_name",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "data_type: DataType",
- "type_info": {
- "Custom": {
- "name": "property_data_type",
- "kind": {
- "Enum": [
- "BOOLEAN",
- "DATE",
- "NUMBER",
- "STRING",
- "SELECT_NUMBER",
- "SELECT_STRING",
- "ENTITY",
- "LINK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 5,
- "name": "is_multi_select",
- "type_info": "Bool"
- },
- {
- "ordinal": 6,
- "name": "specific_entity_type: Option<EntityType>",
- "type_info": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 7,
- "name": "created_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 8,
- "name": "updated_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "is_system",
- "type_info": "Bool"
- }
- ],
- "parameters": {
- "Left": [
- "Int4",
- "Text",
- "Bool"
- ]
- },
- "nullable": [
- false,
- true,
- true,
- false,
- false,
- false,
- true,
- false,
- false,
- false
- ]
- },
- "hash": "827b998f442f5f6cb6ff85dc35f01c5782128a4cb9a020e22ab83a24a6c2b4f5"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-8deba8192e4d2c9e483de10142ec78795082cc722c3f8791b993ecc396ad5fbf.json b/rust/cloud-storage/soup/.sqlx/query-8deba8192e4d2c9e483de10142ec78795082cc722c3f8791b993ecc396ad5fbf.json
deleted file mode 100644
index 4b854f5383..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-8deba8192e4d2c9e483de10142ec78795082cc722c3f8791b993ecc396ad5fbf.json
+++ /dev/null
@@ -1,58 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT\n d.id,\n d.name,\n d.owner,\n d.\"fileType\" as \"file_type\",\n d.\"projectId\" as \"project_id\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\"\n FROM\n \"Document\" d\n WHERE\n d.id = $1 AND d.\"deletedAt\" IS NULL\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "name",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "owner",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "file_type",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 6,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- true,
- true,
- null,
- null
- ]
- },
- "hash": "8deba8192e4d2c9e483de10142ec78795082cc722c3f8791b993ecc396ad5fbf"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json b/rust/cloud-storage/soup/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json
deleted file mode 100644
index 9d717fa5f9..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT property_definition_id, values\n FROM entity_properties\n WHERE entity_id = $1\n AND entity_type = 'TASK'\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "property_definition_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "values",
- "type_info": "Jsonb"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- true
- ]
- },
- "hash": "9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-9e45ba072fbc5266f7edba0fecb99d19192e10139d6ea089be4a3a4a7923361c.json b/rust/cloud-storage/soup/.sqlx/query-9e45ba072fbc5266f7edba0fecb99d19192e10139d6ea089be4a3a4a7923361c.json
deleted file mode 100644
index 357e50473e..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-9e45ba072fbc5266f7edba0fecb99d19192e10139d6ea089be4a3a4a7923361c.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO property_options (\n id,\n property_definition_id,\n display_order,\n number_value,\n string_value\n )\n VALUES ($1, $2, $3, $4, $5)\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid",
- "Uuid",
- "Int4",
- "Float8",
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "9e45ba072fbc5266f7edba0fecb99d19192e10139d6ea089be4a3a4a7923361c"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-b370ac2ac7ace6911ff13454d24ff42b906dcc72b2fb4bcd783b8cb7c06ceab4.json b/rust/cloud-storage/soup/.sqlx/query-b370ac2ac7ace6911ff13454d24ff42b906dcc72b2fb4bcd783b8cb7c06ceab4.json
deleted file mode 100644
index 4ab9cd0461..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-b370ac2ac7ace6911ff13454d24ff42b906dcc72b2fb4bcd783b8cb7c06ceab4.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "DELETE FROM entity_properties WHERE id = $1",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid"
- ]
- },
- "nullable": []
- },
- "hash": "b370ac2ac7ace6911ff13454d24ff42b906dcc72b2fb4bcd783b8cb7c06ceab4"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-b9570b07121de0df914dd0579cc92a5e92973cf114526f80dbe7ab714493090b.json b/rust/cloud-storage/soup/.sqlx/query-b9570b07121de0df914dd0579cc92a5e92973cf114526f80dbe7ab714493090b.json
deleted file mode 100644
index 4063a3122f..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-b9570b07121de0df914dd0579cc92a5e92973cf114526f80dbe7ab714493090b.json
+++ /dev/null
@@ -1,146 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n pd.id,\n pd.organization_id,\n pd.user_id,\n pd.display_name,\n pd.data_type as \"data_type: DataType\",\n pd.is_multi_select,\n pd.specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n pd.created_at,\n pd.updated_at,\n pd.is_system,\n po.id as \"option_id?\",\n po.display_order as \"option_display_order?\",\n po.number_value as option_number_value,\n po.string_value as option_string_value,\n po.created_at as \"option_created_at?\",\n po.updated_at as \"option_updated_at?\"\n FROM property_definitions pd\n LEFT JOIN property_options po ON pd.id = po.property_definition_id\n WHERE \n ($3 AND pd.is_system)\n OR (\n ($1::int IS NOT NULL AND pd.organization_id = $1) \n OR ($2::text IS NOT NULL AND pd.user_id = $2)\n )\n ORDER BY LOWER(pd.display_name), po.display_order, po.number_value, LOWER(po.string_value)\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "organization_id",
- "type_info": "Int4"
- },
- {
- "ordinal": 2,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "display_name",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "data_type: DataType",
- "type_info": {
- "Custom": {
- "name": "property_data_type",
- "kind": {
- "Enum": [
- "BOOLEAN",
- "DATE",
- "NUMBER",
- "STRING",
- "SELECT_NUMBER",
- "SELECT_STRING",
- "ENTITY",
- "LINK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 5,
- "name": "is_multi_select",
- "type_info": "Bool"
- },
- {
- "ordinal": 6,
- "name": "specific_entity_type: Option<EntityType>",
- "type_info": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 7,
- "name": "created_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 8,
- "name": "updated_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "is_system",
- "type_info": "Bool"
- },
- {
- "ordinal": 10,
- "name": "option_id?",
- "type_info": "Uuid"
- },
- {
- "ordinal": 11,
- "name": "option_display_order?",
- "type_info": "Int4"
- },
- {
- "ordinal": 12,
- "name": "option_number_value",
- "type_info": "Float8"
- },
- {
- "ordinal": 13,
- "name": "option_string_value",
- "type_info": "Text"
- },
- {
- "ordinal": 14,
- "name": "option_created_at?",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 15,
- "name": "option_updated_at?",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Int4",
- "Text",
- "Bool"
- ]
- },
- "nullable": [
- false,
- true,
- true,
- false,
- false,
- false,
- true,
- false,
- false,
- false,
- false,
- false,
- true,
- true,
- false,
- false
- ]
- },
- "hash": "b9570b07121de0df914dd0579cc92a5e92973cf114526f80dbe7ab714493090b"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-be27b72f7077a2c90876e68ab617a2c6fc2d39f2c114ad027b7c0dec7f58502a.json b/rust/cloud-storage/soup/.sqlx/query-be27b72f7077a2c90876e68ab617a2c6fc2d39f2c114ad027b7c0dec7f58502a.json
deleted file mode 100644
index afbfe2faca..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-be27b72f7077a2c90876e68ab617a2c6fc2d39f2c114ad027b7c0dec7f58502a.json
+++ /dev/null
@@ -1,145 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": " \n WITH RECURSIVE ProjectHierarchy AS (\n SELECT p.id, uia.access_level \n FROM \"Project\" p\n JOIN \"UserItemAccess\" uia ON p.id = uia.item_id AND uia.item_type = 'project'\n WHERE uia.user_id = $1 AND p.\"deletedAt\" IS NULL\n UNION ALL\n SELECT p.id, ph.access_level\n FROM \"Project\" p \n JOIN ProjectHierarchy ph ON p.\"parentId\" = ph.id\n WHERE p.\"deletedAt\" IS NULL\n ),\n AllAccessGrants AS (\n SELECT item_id, item_type, access_level \n FROM \"UserItemAccess\" \n WHERE user_id = $1\n UNION ALL\n SELECT d.id AS item_id, 'document' AS item_type, ph.access_level\n FROM \"Document\" d \n JOIN ProjectHierarchy ph ON d.\"projectId\" = ph.id\n WHERE d.\"projectId\" IS NOT NULL AND d.\"deletedAt\" IS NULL\n UNION ALL\n SELECT c.id AS item_id, 'chat' AS item_type, ph.access_level\n FROM \"Chat\" c \n JOIN ProjectHierarchy ph ON c.\"projectId\" = ph.id\n WHERE c.\"projectId\" IS NOT NULL AND c.\"deletedAt\" IS NULL\n UNION ALL\n SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level \n FROM ProjectHierarchy ph\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT ON (item_id, item_type) item_id, item_type\n FROM AllAccessGrants\n ORDER BY item_id, item_type, \n CASE access_level\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3 \n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\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 di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\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 = $7\n INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'\n -- This MUST be a LEFT JOIN to support all three sort methods\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' 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\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 NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::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 ON uai.item_id = c.id AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\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 as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::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 )\n SELECT * FROM Combined\n WHERE\n ($4::timestamptz IS NULL)\n OR\n (\"sort_ts!\", \"id!\"::text) < ($4, $5)\n ORDER BY \"sort_ts!\" DESC, \"updated_at!\" DESC\n LIMIT $3\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": "sha",
- "type_info": "Text"
- },
- {
- "ordinal": 14,
- "name": "sub_type?: DocumentSubType",
- "type_info": {
- "Custom": {
- "name": "document_sub_type_value",
- "kind": {
- "Enum": [
- "task"
- ]
- }
- }
- }
- },
- {
- "ordinal": 15,
- "name": "viewed_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 16,
- "name": "sort_ts!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 17,
- "name": "is_completed",
- "type_info": "Bool"
- },
- {
- "ordinal": 18,
- "name": "deleted_at",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- "Int8",
- "Timestamptz",
- "Text",
- "Text",
- "Uuid"
- ]
- },
- "nullable": [
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "be27b72f7077a2c90876e68ab617a2c6fc2d39f2c114ad027b7c0dec7f58502a"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-c12b511f8fbe853ce8e5489db2468ee8a07030cb234bc0a10bc014c493b8e9c2.json b/rust/cloud-storage/soup/.sqlx/query-c12b511f8fbe853ce8e5489db2468ee8a07030cb234bc0a10bc014c493b8e9c2.json
deleted file mode 100644
index e2aa061544..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-c12b511f8fbe853ce8e5489db2468ee8a07030cb234bc0a10bc014c493b8e9c2.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "DELETE FROM entity_properties WHERE entity_id = $1 AND entity_type = $2",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- ]
- },
- "nullable": []
- },
- "hash": "c12b511f8fbe853ce8e5489db2468ee8a07030cb234bc0a10bc014c493b8e9c2"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-c6f8bb6a2a9cda820cf54efb5e4ff8b048d735cfcc23716612f2ee66a8c7151c.json b/rust/cloud-storage/soup/.sqlx/query-c6f8bb6a2a9cda820cf54efb5e4ff8b048d735cfcc23716612f2ee66a8c7151c.json
deleted file mode 100644
index c6b12842de..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-c6f8bb6a2a9cda820cf54efb5e4ff8b048d735cfcc23716612f2ee66a8c7151c.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "DELETE FROM property_options WHERE id = $1",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid"
- ]
- },
- "nullable": []
- },
- "hash": "c6f8bb6a2a9cda820cf54efb5e4ff8b048d735cfcc23716612f2ee66a8c7151c"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-a56dc6f0b90365d68c54ed6af215902f2635372800d9994d89a18c19c11cb69f.json b/rust/cloud-storage/soup/.sqlx/query-db2a1d38763a3639c61d093c4be67c135a99719555af1d4dcf71ae497a56533c.json
similarity index 98%
rename from rust/cloud-storage/soup/.sqlx/query-a56dc6f0b90365d68c54ed6af215902f2635372800d9994d89a18c19c11cb69f.json
rename to rust/cloud-storage/soup/.sqlx/query-db2a1d38763a3639c61d093c4be67c135a99719555af1d4dcf71ae497a56533c.json
index fc43a609a0..598fb6d7d1 100644
--- a/rust/cloud-storage/soup/.sqlx/query-a56dc6f0b90365d68c54ed6af215902f2635372800d9994d89a18c19c11cb69f.json
+++ b/rust/cloud-storage/soup/.sqlx/query-db2a1d38763a3639c61d093c4be67c135a99719555af1d4dcf71ae497a56533c.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n WITH UserAccessibleItems AS (\n SELECT DISTINCT ON (\"item_id\", \"item_type\")\n \"item_id\",\n \"item_type\"\n FROM \"UserItemAccess\" \n WHERE \"user_id\" = $1\n ORDER BY \"item_id\", \"item_type\", \n CASE \"access_level\"\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3 \n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\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 di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\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 = $7\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\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 NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::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\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 as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::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 )\n SELECT * \n FROM Combined\n WHERE ($4::timestamptz IS NULL)\n OR (\"sort_ts!\", \"id!\") < ($4, $5)\n ORDER BY \"sort_ts!\" DESC, \"updated_at!\" DESC\n LIMIT $3\n ",
+ "query": "\n WITH UserAccessibleItems AS (\n SELECT DISTINCT ON (\"item_id\", \"item_type\")\n \"item_id\",\n \"item_type\"\n FROM \"UserItemAccess\" \n WHERE \"user_id\" = $1\n ORDER BY \"item_id\", \"item_type\", \n CASE \"access_level\"\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3 \n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\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 di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\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 = $7\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\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 NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::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\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 as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::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 )\n SELECT * \n FROM Combined\n WHERE ($4::timestamptz IS NULL)\n OR (\"sort_ts!\", \"id!\") < ($4, $5)\n ORDER BY \"sort_ts!\" DESC, \"id!\" DESC\n LIMIT $3\n ",
"describe": {
"columns": [
{
@@ -141,5 +141,5 @@
null
]
},
- "hash": "a56dc6f0b90365d68c54ed6af215902f2635372800d9994d89a18c19c11cb69f"
+ "hash": "db2a1d38763a3639c61d093c4be67c135a99719555af1d4dcf71ae497a56533c"
}
diff --git a/rust/cloud-storage/soup/.sqlx/query-dc836e7dd12a3df4a05ba072af32cb1aca7d6b8c20e636adff6fb3977577e62a.json b/rust/cloud-storage/soup/.sqlx/query-dc836e7dd12a3df4a05ba072af32cb1aca7d6b8c20e636adff6fb3977577e62a.json
deleted file mode 100644
index 2ce75f867a..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-dc836e7dd12a3df4a05ba072af32cb1aca7d6b8c20e636adff6fb3977577e62a.json
+++ /dev/null
@@ -1,52 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT\n t.id,\n t.latest_inbound_message_ts as last_received,\n t.latest_outbound_message_ts as last_sent,\n first_msg.internal_date_ts as thread_started,\n first_msg.subject,\n (SELECT COUNT(*)::bigint FROM email_messages WHERE thread_id = t.id) as \"message_count!\"\n FROM\n email_threads t\n -- LATERAL join to get subject and timestamp from the first message\n LEFT JOIN LATERAL (\n SELECT internal_date_ts, subject\n FROM email_messages\n WHERE thread_id = t.id\n ORDER BY internal_date_ts ASC NULLS LAST\n LIMIT 1\n ) first_msg ON true\n WHERE\n t.id = $1\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "last_received",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 2,
- "name": "last_sent",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 3,
- "name": "thread_started",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 4,
- "name": "subject",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "message_count!",
- "type_info": "Int8"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid"
- ]
- },
- "nullable": [
- false,
- true,
- true,
- true,
- true,
- null
- ]
- },
- "hash": "dc836e7dd12a3df4a05ba072af32cb1aca7d6b8c20e636adff6fb3977577e62a"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-e0b90388e3a9f7dbd1e6586cb0633b0d2d39d64dcc88a0f0c5cd310303e7dc92.json b/rust/cloud-storage/soup/.sqlx/query-e0b90388e3a9f7dbd1e6586cb0633b0d2d39d64dcc88a0f0c5cd310303e7dc92.json
deleted file mode 100644
index a6d8c54236..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-e0b90388e3a9f7dbd1e6586cb0633b0d2d39d64dcc88a0f0c5cd310303e7dc92.json
+++ /dev/null
@@ -1,140 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO property_definitions (\n id,\n organization_id, \n user_id, \n display_name, \n data_type, \n is_multi_select,\n specific_entity_type\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7)\n RETURNING \n id,\n organization_id,\n user_id,\n display_name,\n data_type as \"data_type: DataType\",\n is_multi_select,\n specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n created_at,\n updated_at\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "organization_id",
- "type_info": "Int4"
- },
- {
- "ordinal": 2,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "display_name",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "data_type: DataType",
- "type_info": {
- "Custom": {
- "name": "property_data_type",
- "kind": {
- "Enum": [
- "BOOLEAN",
- "DATE",
- "NUMBER",
- "STRING",
- "SELECT_NUMBER",
- "SELECT_STRING",
- "ENTITY",
- "LINK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 5,
- "name": "is_multi_select",
- "type_info": "Bool"
- },
- {
- "ordinal": 6,
- "name": "specific_entity_type: Option<EntityType>",
- "type_info": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 7,
- "name": "created_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 8,
- "name": "updated_at",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "Int4",
- "Text",
- "Text",
- {
- "Custom": {
- "name": "property_data_type",
- "kind": {
- "Enum": [
- "BOOLEAN",
- "DATE",
- "NUMBER",
- "STRING",
- "SELECT_NUMBER",
- "SELECT_STRING",
- "ENTITY",
- "LINK"
- ]
- }
- }
- },
- "Bool",
- {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- ]
- },
- "nullable": [
- false,
- true,
- true,
- false,
- false,
- false,
- true,
- false,
- false
- ]
- },
- "hash": "e0b90388e3a9f7dbd1e6586cb0633b0d2d39d64dcc88a0f0c5cd310303e7dc92"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-e3502d4611d734fa9d27c17c3adb0785d06317da255894345de287a654f24fc3.json b/rust/cloud-storage/soup/.sqlx/query-e3502d4611d734fa9d27c17c3adb0785d06317da255894345de287a654f24fc3.json
deleted file mode 100644
index 1bb390dc5d..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-e3502d4611d734fa9d27c17c3adb0785d06317da255894345de287a654f24fc3.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "DELETE FROM property_definitions WHERE id = $1",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid"
- ]
- },
- "nullable": []
- },
- "hash": "e3502d4611d734fa9d27c17c3adb0785d06317da255894345de287a654f24fc3"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-edce1ca1979c9bd7c42f7e89d80a8d25037d25951b1f406dddb8d62cc13f74f0.json b/rust/cloud-storage/soup/.sqlx/query-edce1ca1979c9bd7c42f7e89d80a8d25037d25951b1f406dddb8d62cc13f74f0.json
deleted file mode 100644
index 13653d45bf..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-edce1ca1979c9bd7c42f7e89d80a8d25037d25951b1f406dddb8d62cc13f74f0.json
+++ /dev/null
@@ -1,185 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\nSELECT\n ep.id as entity_property_id,\n ep.entity_id,\n ep.entity_type as \"entity_type: EntityType\",\n ep.property_definition_id,\n ep.values as \"values: sqlx::types::JsonValue\",\n ep.created_at as entity_property_created_at,\n ep.updated_at as entity_property_updated_at,\n pd.organization_id as definition_organization_id,\n pd.user_id as definition_user_id,\n pd.display_name,\n pd.data_type as \"data_type: DataType\",\n pd.is_multi_select,\n pd.specific_entity_type as \"specific_entity_type: Option<EntityType>\",\n pd.created_at as definition_created_at,\n pd.updated_at as definition_updated_at,\n pd.is_system as definition_is_system\nFROM entity_properties ep\nINNER JOIN property_definitions pd ON ep.property_definition_id = pd.id\nWHERE (ep.entity_id, ep.entity_type) IN (\n SELECT * FROM UNNEST($1::TEXT[], $2::property_entity_type[])\n)\nAND pd.id = ANY($3::UUID[])\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "entity_property_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "entity_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "entity_type: EntityType",
- "type_info": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 3,
- "name": "property_definition_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 4,
- "name": "values: sqlx::types::JsonValue",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 5,
- "name": "entity_property_created_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 6,
- "name": "entity_property_updated_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "definition_organization_id",
- "type_info": "Int4"
- },
- {
- "ordinal": 8,
- "name": "definition_user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "display_name",
- "type_info": "Text"
- },
- {
- "ordinal": 10,
- "name": "data_type: DataType",
- "type_info": {
- "Custom": {
- "name": "property_data_type",
- "kind": {
- "Enum": [
- "BOOLEAN",
- "DATE",
- "NUMBER",
- "STRING",
- "SELECT_NUMBER",
- "SELECT_STRING",
- "ENTITY",
- "LINK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 11,
- "name": "is_multi_select",
- "type_info": "Bool"
- },
- {
- "ordinal": 12,
- "name": "specific_entity_type: Option<EntityType>",
- "type_info": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- },
- {
- "ordinal": 13,
- "name": "definition_created_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 14,
- "name": "definition_updated_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 15,
- "name": "definition_is_system",
- "type_info": "Bool"
- }
- ],
- "parameters": {
- "Left": [
- "TextArray",
- {
- "Custom": {
- "name": "property_entity_type[]",
- "kind": {
- "Array": {
- "Custom": {
- "name": "property_entity_type",
- "kind": {
- "Enum": [
- "CHANNEL",
- "CHAT",
- "DOCUMENT",
- "PROJECT",
- "THREAD",
- "USER",
- "COMPANY",
- "TASK"
- ]
- }
- }
- }
- }
- }
- },
- "UuidArray"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- true,
- false,
- false,
- true,
- true,
- false,
- false,
- false,
- true,
- false,
- false,
- false
- ]
- },
- "hash": "edce1ca1979c9bd7c42f7e89d80a8d25037d25951b1f406dddb8d62cc13f74f0"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json b/rust/cloud-storage/soup/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json
deleted file mode 100644
index 182e0858ba..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n u.entity_type::property_entity_type,\n u.property_definition_id,\n u.values\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::TEXT[],\n $4::UUID[],\n $5::JSONB[]\n ) AS u(id, entity_id, entity_type, property_definition_id, values)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO UPDATE SET \n values = EXCLUDED.values,\n updated_at = NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "TextArray",
- "UuidArray",
- "JsonbArray"
- ]
- },
- "nullable": []
- },
- "hash": "f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069"
-}
diff --git a/rust/cloud-storage/soup/src/domain/service.rs b/rust/cloud-storage/soup/src/domain/service.rs
index cb6ffaeafa..8fd644fcff 100644
--- a/rust/cloud-storage/soup/src/domain/service.rs
+++ b/rust/cloud-storage/soup/src/domain/service.rs
@@ -65,6 +65,7 @@ where
}
}
+ #[tracing::instrument(err, skip(self, req))]
async fn handle_simple_request(
&self,
soup_type: SoupType,
@@ -89,6 +90,7 @@ where
}))
}
+ #[tracing::instrument(skip(self, req))]
async fn handle_soup_by_ids(
&self,
soup_type: SoupType,
@@ -101,6 +103,7 @@ where
}
/// enriches a frecency response with further soup data if the initial results length was not long enough
+ #[tracing::instrument(err, skip(self, frecency_items))]
async fn fallback_soup_data(
&self,
soup_type: SoupType,
@@ -127,6 +130,7 @@ where
Ok(frecency_items.chain(updated_at_soup))
}
+ #[tracing::instrument(err, skip(self, cursor))]
async fn handle_advanced_sort(
&self,
cursor: Query<Uuid, Frecency, Option<EntityFilterAst>>,
@@ -199,6 +203,7 @@ where
))
}
+ #[tracing::instrument(err, skip(self, from_value))]
async fn handle_frecency_cursor(
&self,
from_value: Option<(f64, Option<EntityFilterAst>)>,
@@ -253,6 +258,7 @@ where
})
}
+ #[tracing::instrument(err, skip(self, req))]
async fn handle_email_request(
&self,
req: Option<GetEmailsRequest>,
@@ -309,6 +315,7 @@ where
Ok(Either::Right(emails_with_props.into_iter()))
}
+ #[tracing::instrument(err, skip(self, req))]
async fn handle_comms_request(
&self,
req: Option<GetChannelsRequest>,
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo.rs
index aaeb2b7a95..c9f7b08d5b 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo.rs
@@ -144,6 +144,7 @@ fn type_err<E: std::fmt::Display>(e: E) -> sqlx::Error {
/// This helper collects entity references from items that support properties,
/// fetches their properties in bulk, and assigns them to each item.
/// Tasks use `EntityType::Task` while regular documents use `EntityType::Document`.
+#[tracing::instrument(err, skip(db, items))]
pub(crate) async fn populate_properties(
db: &PgPool,
items: &mut [SoupItem],
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs
index cf6b3b7b24..98f9a133c7 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs
@@ -33,49 +33,153 @@ pub async fn expanded_generic_cursor_soup(
let completed_option_id = StatusOption::COMPLETED_UUID.to_string();
let mut items: Vec<SoupItem> = sqlx::query!(
-r#"
+r#"
+ -- =============================================================================
+ -- EXPANDED GENERIC CURSOR SOUP QUERY
+ -- =============================================================================
+ -- Retrieves all items (documents, chats, projects) that a user has access to,
+ -- including both explicit permissions and inherited permissions through the
+ -- project hierarchy.
+ -- =============================================================================
+
+ -- Build the project hierarchy tree using recursive CTE.
+ -- Starting from projects the user has explicit access to, recursively find
+ -- all child projects. This enables inherited access - if you can access a
+ -- parent project, you can access all its descendants.
WITH RECURSIVE ProjectHierarchy AS (
- SELECT p.id, uia.access_level
+ -- Base case: projects the user has direct access to
+ SELECT p.id, uia.access_level
FROM "Project" p
JOIN "UserItemAccess" uia ON p.id = uia.item_id AND uia.item_type = 'project'
WHERE uia.user_id = $1 AND p."deletedAt" IS NULL
UNION ALL
+ -- Recursive case: find child projects, inheriting parent's access level
SELECT p.id, ph.access_level
- FROM "Project" p
+ FROM "Project" p
JOIN ProjectHierarchy ph ON p."parentId" = ph.id
WHERE p."deletedAt" IS NULL
),
+
+ -- Collect all access grants from multiple sources.
+ -- Aggregates explicit permissions AND implicit permissions inherited
+ -- through project membership.
AllAccessGrants AS (
- SELECT item_id, item_type, access_level
- FROM "UserItemAccess"
+ -- Direct/explicit access grants to any item type
+ SELECT item_id, item_type, access_level
+ FROM "UserItemAccess"
WHERE user_id = $1
+
UNION ALL
- SELECT d.id AS item_id, 'document' AS item_type, ph.access_level
- FROM "Document" d
- JOIN ProjectHierarchy ph ON d."projectId" = ph.id
- WHERE d."projectId" IS NOT NULL AND d."deletedAt" IS NULL
+
+ -- Documents within accessible projects (inherited access).
+ -- Uses ANY(ARRAY(...)) pattern to reduce intermediate result set size.
+ SELECT d.id AS item_id, 'document' AS item_type,
+ (SELECT ph.access_level FROM ProjectHierarchy ph WHERE ph.id = d."projectId" LIMIT 1) as access_level
+ FROM "Document" d
+ WHERE d."projectId" = ANY(ARRAY(SELECT id FROM ProjectHierarchy))
+ AND d."deletedAt" IS NULL
+
UNION ALL
+
+ -- Chats within accessible projects (inherited access)
SELECT c.id AS item_id, 'chat' AS item_type, ph.access_level
- FROM "Chat" c
+ FROM "Chat" c
JOIN ProjectHierarchy ph ON c."projectId" = ph.id
WHERE c."projectId" IS NOT NULL AND c."deletedAt" IS NULL
+
UNION ALL
- SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level
+
+ -- The projects themselves from the hierarchy
+ SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level
FROM ProjectHierarchy ph
),
+
+ -- Deduplicate access grants, keeping the highest permission level.
+ -- When a user has multiple access paths to the same item (e.g., direct + inherited),
+ -- we keep only one row with the highest privilege level.
UserAccessibleItems AS (
SELECT DISTINCT ON (item_id, item_type) item_id, item_type
FROM AllAccessGrants
- ORDER BY item_id, item_type,
+ ORDER BY item_id, item_type,
+ -- Priority: owner > edit > comment > view
CASE access_level
WHEN 'owner' THEN 4
- WHEN 'edit' THEN 3
+ WHEN 'edit' THEN 3
WHEN 'comment' THEN 2
WHEN 'view' THEN 1
ELSE 0
END DESC
),
- Combined AS (
+
+ -- Identify the top N items with minimal columns before joining full details.
+ -- Performs early filtering and sorting to reduce the data processed in
+ -- subsequent joins.
+ TopItems AS (
+ SELECT item_type, id, sort_ts, updated_at FROM (
+ SELECT
+ 'document'::text as item_type,
+ d.id,
+ -- Dynamic sort column based on user's selected sort method
+ CASE $2
+ WHEN 'viewed_updated' THEN COALESCE(uh."updatedAt", d."updatedAt")
+ WHEN 'viewed_at' THEN COALESCE(uh."updatedAt", '1970-01-01 00:00:00+00')
+ WHEN 'created_at' THEN d."createdAt"
+ ELSE d."updatedAt"
+ END::timestamptz as sort_ts,
+ d."updatedAt"::timestamptz as updated_at
+ FROM "Document" d
+ 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' AND uh."userId" = $1
+ WHERE d."deletedAt" IS NULL
+
+ UNION ALL
+
+ SELECT
+ 'chat'::text,
+ c.id,
+ CASE $2
+ WHEN 'viewed_updated' THEN COALESCE(uh."updatedAt", c."updatedAt")
+ WHEN 'viewed_at' THEN COALESCE(uh."updatedAt", '1970-01-01 00:00:00+00')
+ WHEN 'created_at' THEN c."createdAt"
+ ELSE c."updatedAt"
+ END::timestamptz,
+ c."updatedAt"::timestamptz
+ 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
+
+ UNION ALL
+
+ SELECT
+ 'project'::text,
+ p.id,
+ CASE $2
+ WHEN 'viewed_updated' THEN COALESCE(uh."updatedAt", p."updatedAt")
+ WHEN 'viewed_at' THEN COALESCE(uh."updatedAt", '1970-01-01 00:00:00+00')
+ WHEN 'created_at' THEN p."createdAt"
+ ELSE p."updatedAt"
+ END::timestamptz,
+ p."updatedAt"::timestamptz
+ 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
+ ) all_items
+ WHERE
+ -- Cursor-based pagination: skip items we've already seen.
+ -- NULL cursor means first page (no items to skip).
+ ($4::timestamptz IS NULL)
+ OR
+ -- Seek method: find items "before" the cursor position
+ -- using (sort_ts, id) tuple comparison for deterministic ordering
+ (sort_ts, id::text) < ($4, $5)
+ ORDER BY sort_ts DESC, id DESC
+ LIMIT $3
+ )
+
+ -- Join full item details only for the filtered top items.
+ SELECT * FROM (
SELECT
'document' as "item_type!",
d.id as "id!",
@@ -93,12 +197,8 @@ r#"
di.sha as "sha",
dt.sub_type as "sub_type?: DocumentSubType",
uh."updatedAt"::timestamptz as "viewed_at",
- CASE $2
- WHEN 'viewed_updated' THEN COALESCE(uh."updatedAt", d."updatedAt")
- WHEN 'viewed_at' THEN COALESCE(uh."updatedAt", '1970-01-01 00:00:00+00')
- WHEN 'created_at' THEN d."createdAt"
- ELSE d."updatedAt"
- END::timestamptz as "sort_ts!",
+ t.sort_ts as "sort_ts!",
+ -- Task completion status: check if status property matches "completed"
CASE
WHEN dt.sub_type = 'task'
AND ep_status.values->'value' ? $6
@@ -108,16 +208,17 @@ r#"
ELSE NULL
END as "is_completed",
d."deletedAt"::timestamptz as "deleted_at"
- FROM "Document" d
+ FROM TopItems t
+ INNER JOIN "Document" d ON d.id = t.id
LEFT JOIN document_sub_type dt ON dt.document_id = d.id
LEFT JOIN entity_properties ep_status
ON dt.sub_type = 'task'
AND ep_status.entity_id = d.id
AND ep_status.entity_type = 'TASK'
AND ep_status.property_definition_id = $7
- INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'
- -- This MUST be a LEFT JOIN to support all three sort methods
- LEFT JOIN "UserHistory" uh ON uh."itemId" = d.id AND uh."itemType" = 'document' AND uh."userId" = $1
+ LEFT JOIN "UserHistory" uh
+ ON uh."itemId" = d.id AND uh."itemType" = 'document' AND uh."userId" = $1
+ -- LATERAL joins to get the latest version info
LEFT JOIN LATERAL (
SELECT b.id
FROM "DocumentBom" b
@@ -132,7 +233,7 @@ r#"
ORDER BY i."updatedAt" DESC
LIMIT 1
) di ON true
- WHERE d."deletedAt" IS NULL
+ WHERE t.item_type = 'document'
UNION ALL
@@ -153,18 +254,14 @@ r#"
NULL as "sha",
NULL as "sub_type",
uh."updatedAt"::timestamptz as "viewed_at",
- CASE $2
- WHEN 'viewed_updated' THEN COALESCE(uh."updatedAt", c."updatedAt")
- WHEN 'viewed_at' THEN COALESCE(uh."updatedAt", '1970-01-01 00:00:00+00')
- WHEN 'created_at' THEN c."createdAt"
- ELSE c."updatedAt"
- END::timestamptz as "sort_ts!",
+ t.sort_ts as "sort_ts!",
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
+ FROM TopItems t
+ INNER JOIN "Chat" c ON c.id = t.id
+ LEFT JOIN "UserHistory" uh
+ ON uh."itemId" = c.id AND uh."itemType" = 'chat' AND uh."userId" = $1
+ WHERE t.item_type = 'chat'
UNION ALL
@@ -185,30 +282,19 @@ r#"
NULL as "sha",
NULL as "sub_type",
uh."updatedAt"::timestamptz as "viewed_at",
- CASE $2
- WHEN 'viewed_updated' THEN COALESCE(uh."updatedAt", p."updatedAt")
- WHEN 'viewed_at' THEN COALESCE(uh."updatedAt", '1970-01-01 00:00:00+00')
- WHEN 'created_at' THEN p."createdAt"
- ELSE p."updatedAt"
- END::timestamptz as "sort_ts!",
+ t.sort_ts as "sort_ts!",
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'
+ FROM TopItems t
+ INNER JOIN "Project" p ON p.id = t.id
LEFT JOIN "UserHistory" uh
- ON uh."itemId" = p.id
- AND uh."itemType" = 'project'
- AND uh."userId" = $1
- WHERE p."deletedAt" IS NULL
- )
- SELECT * FROM Combined
- WHERE
- ($4::timestamptz IS NULL)
- OR
- ("sort_ts!", "id!"::text) < ($4, $5)
- ORDER BY "sort_ts!" DESC, "updated_at!" DESC
+ ON uh."itemId" = p.id AND uh."itemType" = 'project' AND uh."userId" = $1
+ WHERE t.item_type = 'project'
+ ) Combined
+ -- Sort by timestamp descending, with ID as tiebreaker for deterministic pagination.
+ -- This ensures consistent ordering when multiple items share the same timestamp,
+ -- preventing items from being skipped or duplicated across pages.
+ ORDER BY "sort_ts!" DESC, "id!" DESC
LIMIT $3
"#,
user_id.as_ref(), // $1
@@ -427,7 +513,7 @@ r#"
OR
(Combined."sort_ts!", Combined."id!"::text) < ($4, $5)
)
- ORDER BY Combined."sort_ts!" DESC, Combined."updated_at!" DESC
+ ORDER BY Combined."sort_ts!" DESC, Combined."id!" DESC
LIMIT $3
"#,
user_id.as_ref(), // $1
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
index f7a68c507d..933139094c 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
@@ -18,6 +18,7 @@ use uuid::Uuid;
/// the requested items, those items WILL be included in the results even if the user doesn't
/// have explicit permissions on them. Project items themselves are excluded from results -
/// only documents and chats are returned. Results are sorted to match the input entity order.
+#[tracing::instrument(err, skip(db, entities))]
pub async fn expanded_soup_by_ids<'a>(
db: &PgPool,
user_id: MacroUserIdStr<'_>,
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs
index 2f784d3b89..199db19757 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs
@@ -208,7 +208,7 @@ static SUFFIX: &str = r#"
($4::timestamptz IS NULL)
OR
("sort_ts", "id"::text) < ($4, $5)
- ORDER BY "sort_ts" DESC, "updated_at" DESC
+ ORDER BY "sort_ts" DESC, "id" DESC
LIMIT $3
"#;
@@ -224,7 +224,7 @@ static SUFFIX_NO_FRECENCY: &str = r#"
OR
(Combined."sort_ts", Combined."id"::text) < ($4, $5)
)
- ORDER BY Combined."sort_ts" DESC, Combined."updated_at" DESC
+ ORDER BY Combined."sort_ts" DESC, Combined."id" DESC
LIMIT $3
"#;
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs
index e4dcd00c48..34c8d9fc9b 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs
@@ -95,12 +95,13 @@ async fn test_viewed_at_orders_nulls_last(pool: Pool<Postgres>) -> anyhow::Resul
Uuid::parse_str("11111111-0000-0000-0000-000000000000").unwrap(), // doc-standalone - 2024-01-06
Uuid::parse_str("11111111-dddd-dddd-dddd-dddddddddddd").unwrap(), // doc-in-D - 2023-01-05
Uuid::parse_str("22222222-cccc-cccc-cccc-cccccccccccc").unwrap(), // chat-in-C - 2023-01-04
- Uuid::parse_str("22222222-bbbb-bbbb-bbbb-bbbbbbbbbbbb").unwrap(), // chat-in-B - null
- Uuid::parse_str("11111111-cccc-cccc-cccc-cccccccccccc").unwrap(), // doc-in-C - null
+ // Null viewed_at items, tiebroken by id DESC:
Uuid::parse_str("dddddddd-ffff-ffff-ffff-ffffffffffff").unwrap(), // project-D - null
Uuid::parse_str("cccccccc-ffff-ffff-ffff-ffffffffffff").unwrap(), // project-C - null
Uuid::parse_str("bbbbbbbb-ffff-ffff-ffff-ffffffffffff").unwrap(), // project-B - null
Uuid::parse_str("aaaaaaaa-ffff-ffff-ffff-ffffffffffff").unwrap(), // project-A - null
+ Uuid::parse_str("22222222-bbbb-bbbb-bbbb-bbbbbbbbbbbb").unwrap(), // chat-in-B - null
+ Uuid::parse_str("11111111-cccc-cccc-cccc-cccccccccccc").unwrap(), // doc-in-C - null
];
assert_eq!(
ordered_ids, expected_order,
@@ -243,9 +244,9 @@ async fn test_expanded_generic_sorting_methods(pool: Pool<Postgres>) -> anyhow::
"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // doc-A
"bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // doc-B
"aaaaaaaa-cccc-cccc-cccc-cccccccccccc", // chat-A
- "bbbbbbbb-cccc-cccc-cccc-cccccccccccc", // chat-B
- "bbbbbbbb-ffff-ffff-ffff-ffffffffffff", // project-B
- "aaaaaaaa-ffff-ffff-ffff-ffffffffffff", // project-A
+ "bbbbbbbb-ffff-ffff-ffff-ffffffffffff", // project-B (epoch, tiebroken by id DESC)
+ "bbbbbbbb-cccc-cccc-cccc-cccccccccccc", // chat-B (epoch, tiebroken by id DESC)
+ "aaaaaaaa-ffff-ffff-ffff-ffffffffffff", // project-A (epoch, tiebroken by id DESC)
]
.iter()
.map(|&s| Uuid::parse_str(s).unwrap())
@@ -2520,3 +2521,883 @@ async fn test_expanded_dynamic_cursor_populates_properties(
Ok(())
}
+
+// ============================================================================
+// Exhaustive expanded_generic_cursor_soup tests
+// ============================================================================
+
+// Fixture constants for expanded_cursor_soup_exhaustive
+const EX_PROJECT_ROOT: &str = "aa000001-ffff-ffff-ffff-ffffffffffff";
+const EX_PROJECT_MID: &str = "aa000002-ffff-ffff-ffff-ffffffffffff";
+const EX_PROJECT_DEEP: &str = "aa000003-ffff-ffff-ffff-ffffffffffff";
+const EX_PROJECT_ISOLATED: &str = "aa000004-ffff-ffff-ffff-ffffffffffff";
+const EX_DOC_ROOT: &str = "bb000001-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+const EX_DOC_MID: &str = "bb000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+const EX_DOC_DEEP: &str = "bb000003-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+const EX_DOC_STANDALONE: &str = "bb000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+const EX_DOC_DELETED: &str = "bb000005-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+const EX_DOC_TASK_COMPLETED: &str = "bb000006-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+const EX_DOC_TASK_INCOMPLETE: &str = "bb000007-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+const EX_DOC_TASK_NO_STATUS: &str = "bb000008-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+const EX_DOC_ISOLATED: &str = "bb000009-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+const EX_CHAT_ROOT: &str = "cc000001-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+const EX_CHAT_STANDALONE: &str = "cc000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+const EX_CHAT_DELETED: &str = "cc000003-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+const EX_CHAT_ISOLATED: &str = "cc000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+
+fn uuid(s: &str) -> Uuid {
+ Uuid::parse_str(s).unwrap()
+}
+
+/// Deleted documents and chats must not appear in results
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_deleted_items_excluded(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::UpdatedAt, ()),
+ )
+ .await?;
+
+ let ids: HashSet<Uuid> = items.iter().map(|i| i.id()).collect();
+
+ assert!(
+ !ids.contains(&uuid(EX_DOC_DELETED)),
+ "Deleted document must not appear"
+ );
+ assert!(
+ !ids.contains(&uuid(EX_CHAT_DELETED)),
+ "Deleted chat must not appear"
+ );
+
+ Ok(())
+}
+
+/// Items in isolated project must not appear for user-1.
+/// Isolated project, doc, and chat should all be excluded.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_access_control_excludes_isolated(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::UpdatedAt, ()),
+ )
+ .await?;
+
+ let ids: HashSet<Uuid> = items.iter().map(|i| i.id()).collect();
+
+ assert!(
+ !ids.contains(&uuid(EX_PROJECT_ISOLATED)),
+ "Isolated project must not appear for user-1"
+ );
+ assert!(
+ !ids.contains(&uuid(EX_DOC_ISOLATED)),
+ "Isolated doc must not appear for user-1"
+ );
+ assert!(
+ !ids.contains(&uuid(EX_CHAT_ISOLATED)),
+ "Isolated chat must not appear for user-1"
+ );
+
+ Ok(())
+}
+
+/// User-2 only has access to the isolated project and its children.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_user_isolation(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::UpdatedAt, ()),
+ )
+ .await?;
+
+ let ids: HashSet<Uuid> = items.iter().map(|i| i.id()).collect();
+
+ let expected: HashSet<Uuid> = [EX_PROJECT_ISOLATED, EX_DOC_ISOLATED, EX_CHAT_ISOLATED]
+ .iter()
+ .map(|s| uuid(s))
+ .collect();
+
+ assert_eq!(
+ ids, expected,
+ "User-2 should only see isolated project, its doc, and its chat"
+ );
+
+ Ok(())
+}
+
+/// Documents 3 levels deep in the hierarchy (root -> mid -> deep) are accessible
+/// through inherited project permissions.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_deep_hierarchy_access(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::UpdatedAt, ()),
+ )
+ .await?;
+
+ let ids: HashSet<Uuid> = items.iter().map(|i| i.id()).collect();
+
+ // All hierarchy items should be present
+ assert!(ids.contains(&uuid(EX_PROJECT_ROOT)), "project-root");
+ assert!(ids.contains(&uuid(EX_PROJECT_MID)), "project-mid");
+ assert!(ids.contains(&uuid(EX_PROJECT_DEEP)), "project-deep");
+ assert!(ids.contains(&uuid(EX_DOC_ROOT)), "doc-in-root");
+ assert!(ids.contains(&uuid(EX_DOC_MID)), "doc-in-mid");
+ assert!(ids.contains(&uuid(EX_DOC_DEEP)), "doc-in-deep (3 levels)");
+ assert!(ids.contains(&uuid(EX_CHAT_ROOT)), "chat-in-root");
+
+ // Standalone items with direct access
+ assert!(ids.contains(&uuid(EX_DOC_STANDALONE)), "doc-standalone");
+ assert!(ids.contains(&uuid(EX_CHAT_STANDALONE)), "chat-standalone");
+
+ // Task documents in root
+ assert!(
+ ids.contains(&uuid(EX_DOC_TASK_COMPLETED)),
+ "doc-task-completed"
+ );
+ assert!(
+ ids.contains(&uuid(EX_DOC_TASK_INCOMPLETE)),
+ "doc-task-incomplete"
+ );
+ assert!(
+ ids.contains(&uuid(EX_DOC_TASK_NO_STATUS)),
+ "doc-task-no-status"
+ );
+
+ // Total should be 12: 3 projects + 7 docs + 2 chats
+ assert_eq!(items.len(), 12, "User-1 should see exactly 12 items");
+
+ Ok(())
+}
+
+/// Task documents should have correct is_completed values:
+/// - Completed task -> Some(Task { is_completed: true })
+/// - Incomplete task -> Some(Task { is_completed: false })
+/// - Task with no status property -> Some(Task { is_completed: false })
+/// - Non-task documents -> sub_type is None
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_task_completion_status(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ use models_soup::document::SoupDocumentSubType;
+
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::UpdatedAt, ()),
+ )
+ .await?;
+
+ let items_map: std::collections::HashMap<Uuid, &SoupItem> =
+ items.iter().map(|i| (i.id(), i)).collect();
+
+ // Completed task
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_TASK_COMPLETED)], SoupItem::Document);
+ match &doc.sub_type {
+ Some(SoupDocumentSubType::Task { is_completed }) => {
+ assert!(is_completed, "Completed task should have is_completed=true");
+ }
+ other => panic!("Expected Task sub_type, got {:?}", other),
+ }
+
+ // Incomplete task (status = In Progress)
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_TASK_INCOMPLETE)], SoupItem::Document);
+ match &doc.sub_type {
+ Some(SoupDocumentSubType::Task { is_completed }) => {
+ assert!(
+ !is_completed,
+ "Incomplete task should have is_completed=false"
+ );
+ }
+ other => panic!("Expected Task sub_type, got {:?}", other),
+ }
+
+ // Task with no status property
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_TASK_NO_STATUS)], SoupItem::Document);
+ match &doc.sub_type {
+ Some(SoupDocumentSubType::Task { is_completed }) => {
+ assert!(
+ !is_completed,
+ "Task with no status should have is_completed=false"
+ );
+ }
+ other => panic!("Expected Task sub_type, got {:?}", other),
+ }
+
+ // Non-task document
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_ROOT)], SoupItem::Document);
+ assert!(
+ doc.sub_type.is_none(),
+ "Non-task document should have sub_type=None"
+ );
+
+ Ok(())
+}
+
+/// Test UpdatedAt sort ordering.
+/// Items sorted by updatedAt DESC, tiebreaker by updatedAt DESC.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_sort_updated_at(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::UpdatedAt, ()),
+ )
+ .await?;
+
+ let ids: Vec<Uuid> = items.iter().map(|i| i.id()).collect();
+
+ // updatedAt DESC:
+ // chat-standalone 2024-03-11
+ // doc-in-deep 2024-03-10
+ // project-deep 2024-02-12
+ // project-mid 2024-02-11
+ // project-root 2024-02-10
+ // chat-in-root 2024-02-08
+ // doc-task-no-status 2024-02-07
+ // doc-task-incomplete 2024-02-06
+ // doc-task-completed 2024-02-05
+ // doc-standalone 2024-02-04
+ // doc-in-mid 2024-02-02
+ // doc-in-root 2024-02-01
+ let expected: Vec<Uuid> = [
+ EX_CHAT_STANDALONE,
+ EX_DOC_DEEP,
+ EX_PROJECT_DEEP,
+ EX_PROJECT_MID,
+ EX_PROJECT_ROOT,
+ EX_CHAT_ROOT,
+ EX_DOC_TASK_NO_STATUS,
+ EX_DOC_TASK_INCOMPLETE,
+ EX_DOC_TASK_COMPLETED,
+ EX_DOC_STANDALONE,
+ EX_DOC_MID,
+ EX_DOC_ROOT,
+ ]
+ .iter()
+ .map(|s| uuid(s))
+ .collect();
+
+ assert_eq!(ids, expected, "UpdatedAt sort order is wrong");
+
+ Ok(())
+}
+
+/// Test CreatedAt sort ordering.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_sort_created_at(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::CreatedAt, ()),
+ )
+ .await?;
+
+ let ids: Vec<Uuid> = items.iter().map(|i| i.id()).collect();
+
+ // createdAt DESC:
+ // project-deep 2024-01-12
+ // project-mid 2024-01-11
+ // project-root 2024-01-10
+ // chat-standalone 2024-01-09
+ // chat-in-root 2024-01-08
+ // doc-task-no-status 2024-01-07
+ // doc-task-incomplete 2024-01-06
+ // doc-task-completed 2024-01-05
+ // doc-standalone 2024-01-04
+ // doc-in-deep 2024-01-03
+ // doc-in-mid 2024-01-02
+ // doc-in-root 2024-01-01
+ let expected: Vec<Uuid> = [
+ EX_PROJECT_DEEP,
+ EX_PROJECT_MID,
+ EX_PROJECT_ROOT,
+ EX_CHAT_STANDALONE,
+ EX_CHAT_ROOT,
+ EX_DOC_TASK_NO_STATUS,
+ EX_DOC_TASK_INCOMPLETE,
+ EX_DOC_TASK_COMPLETED,
+ EX_DOC_STANDALONE,
+ EX_DOC_DEEP,
+ EX_DOC_MID,
+ EX_DOC_ROOT,
+ ]
+ .iter()
+ .map(|s| uuid(s))
+ .collect();
+
+ assert_eq!(ids, expected, "CreatedAt sort order is wrong");
+
+ Ok(())
+}
+
+/// Test ViewedAt sort ordering.
+/// Items with history sorted by UserHistory.updatedAt DESC.
+/// Items without history get sort_ts = epoch, tiebroken by id DESC.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_sort_viewed_at(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::ViewedAt, ()),
+ )
+ .await?;
+
+ let ids: Vec<Uuid> = items.iter().map(|i| i.id()).collect();
+
+ // With history (by UserHistory.updatedAt DESC):
+ // doc-in-mid 2024-03-08
+ // doc-task-no-status 2024-03-07
+ // doc-standalone 2024-03-06
+ // doc-in-root 2024-03-05
+ // doc-task-completed 2024-03-04
+ // chat-in-root 2024-03-03
+ // project-root 2024-03-02
+ // project-deep 2024-03-01
+ // Without history (sort_ts = epoch, tiebroken by id DESC):
+ // chat-standalone (epoch, id cc000002)
+ // doc-task-incomplete (epoch, id bb000007)
+ // doc-in-deep (epoch, id bb000003)
+ // project-mid (epoch, id aa000002)
+ let expected: Vec<Uuid> = [
+ EX_DOC_MID,
+ EX_DOC_TASK_NO_STATUS,
+ EX_DOC_STANDALONE,
+ EX_DOC_ROOT,
+ EX_DOC_TASK_COMPLETED,
+ EX_CHAT_ROOT,
+ EX_PROJECT_ROOT,
+ EX_PROJECT_DEEP,
+ EX_CHAT_STANDALONE,
+ EX_DOC_TASK_INCOMPLETE,
+ EX_DOC_DEEP,
+ EX_PROJECT_MID,
+ ]
+ .iter()
+ .map(|s| uuid(s))
+ .collect();
+
+ assert_eq!(ids, expected, "ViewedAt sort order is wrong");
+
+ Ok(())
+}
+
+/// Test ViewedUpdated sort ordering.
+/// Uses COALESCE(uh.updatedAt, item.updatedAt) instead of falling back to epoch.
+/// This means items without history use their updatedAt, which produces a
+/// different ordering than ViewedAt for items with high updatedAt but no history.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_sort_viewed_updated(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::ViewedUpdated, ()),
+ )
+ .await?;
+
+ let ids: Vec<Uuid> = items.iter().map(|i| i.id()).collect();
+
+ // COALESCE(uh.updatedAt, item.updatedAt) DESC:
+ // chat-standalone no history -> updatedAt 2024-03-11
+ // doc-in-deep no history -> updatedAt 2024-03-10
+ // doc-in-mid history 2024-03-08
+ // doc-task-no-status history 2024-03-07
+ // doc-standalone history 2024-03-06
+ // doc-in-root history 2024-03-05
+ // doc-task-completed history 2024-03-04
+ // chat-in-root history 2024-03-03
+ // project-root history 2024-03-02
+ // project-deep history 2024-03-01
+ // project-mid no history -> updatedAt 2024-02-11
+ // doc-task-incomplete no history -> updatedAt 2024-02-06
+ let expected: Vec<Uuid> = [
+ EX_CHAT_STANDALONE,
+ EX_DOC_DEEP,
+ EX_DOC_MID,
+ EX_DOC_TASK_NO_STATUS,
+ EX_DOC_STANDALONE,
+ EX_DOC_ROOT,
+ EX_DOC_TASK_COMPLETED,
+ EX_CHAT_ROOT,
+ EX_PROJECT_ROOT,
+ EX_PROJECT_DEEP,
+ EX_PROJECT_MID,
+ EX_DOC_TASK_INCOMPLETE,
+ ]
+ .iter()
+ .map(|s| uuid(s))
+ .collect();
+
+ assert_eq!(ids, expected, "ViewedUpdated sort order is wrong");
+
+ // Verify viewed_updated produces a DIFFERENT order than viewed_at
+ let viewed_at_items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::ViewedAt, ()),
+ )
+ .await?;
+ let viewed_at_ids: Vec<Uuid> = viewed_at_items.iter().map(|i| i.id()).collect();
+
+ assert_ne!(
+ ids, viewed_at_ids,
+ "ViewedUpdated and ViewedAt should produce different orderings"
+ );
+
+ Ok(())
+}
+
+/// Walking through all items one at a time with limit=1 should yield every item
+/// exactly once, in the correct order, with no duplicates.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_paginate_one_at_a_time(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let sort = SimpleSortMethod::UpdatedAt;
+
+ let mut all_ids: Vec<Uuid> = Vec::new();
+ let mut current_query: Query<Uuid, SimpleSortMethod, ()> = Query::Sort(sort, ());
+
+ loop {
+ let result = expanded_generic_cursor_soup(&pool, user_id.copied(), 1, current_query)
+ .await?
+ .into_iter()
+ .paginate_on(1, sort)
+ .into_page();
+
+ all_ids.extend(result.items.iter().map(|i| i.id()));
+
+ match result.next_cursor {
+ Some(cursor) => {
+ let decoded = cursor.decode_json().unwrap();
+ current_query = Query::new(
+ Some(models_pagination::Cursor {
+ id: decoded.id,
+ limit: decoded.limit,
+ val: decoded.val,
+ filter: decoded.filter,
+ }),
+ sort,
+ (),
+ );
+ }
+ None => break,
+ }
+ }
+
+ assert_eq!(all_ids.len(), 12, "Should walk through all 12 items");
+
+ let unique: HashSet<Uuid> = all_ids.iter().copied().collect();
+ assert_eq!(
+ unique.len(),
+ 12,
+ "No duplicates when paginating one at a time"
+ );
+
+ // Verify order matches a single large fetch
+ let all_at_once =
+ expanded_generic_cursor_soup(&pool, user_id.copied(), 50, Query::Sort(sort, ())).await?;
+ let expected_ids: Vec<Uuid> = all_at_once.iter().map(|i| i.id()).collect();
+ assert_eq!(
+ all_ids, expected_ids,
+ "Paginated order should match single-fetch order"
+ );
+
+ Ok(())
+}
+
+/// Full pagination walk with page size of 3. Verifies no duplicates
+/// and correct total count across all pages for each sort method.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_paginate_all_sort_methods(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let page_size: u16 = 3;
+
+ for sort in [
+ SimpleSortMethod::ViewedAt,
+ SimpleSortMethod::UpdatedAt,
+ SimpleSortMethod::CreatedAt,
+ SimpleSortMethod::ViewedUpdated,
+ ] {
+ let mut all_ids: Vec<Uuid> = Vec::new();
+ let mut current_query: Query<Uuid, SimpleSortMethod, ()> = Query::Sort(sort, ());
+ let mut page_count = 0;
+
+ loop {
+ let result =
+ expanded_generic_cursor_soup(&pool, user_id.copied(), page_size, current_query)
+ .await?
+ .into_iter()
+ .paginate_on(page_size as usize, sort)
+ .into_page();
+
+ all_ids.extend(result.items.iter().map(|i| i.id()));
+ page_count += 1;
+
+ match result.next_cursor {
+ Some(cursor) => {
+ let decoded = cursor.decode_json().unwrap();
+ current_query = Query::new(
+ Some(models_pagination::Cursor {
+ id: decoded.id,
+ limit: decoded.limit,
+ val: decoded.val,
+ filter: decoded.filter,
+ }),
+ sort,
+ (),
+ );
+ }
+ None => break,
+ }
+ }
+
+ assert_eq!(
+ all_ids.len(),
+ 12,
+ "Sort {:?}: should get all 12 items across pages",
+ sort
+ );
+
+ let unique: HashSet<Uuid> = all_ids.iter().copied().collect();
+ assert_eq!(
+ unique.len(),
+ 12,
+ "Sort {:?}: no duplicates across pages",
+ sort
+ );
+ }
+
+ Ok(())
+}
+
+/// Limit larger than total items returns everything in one page.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_limit_larger_than_total(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 1000,
+ Query::Sort(SimpleSortMethod::UpdatedAt, ()),
+ )
+ .await?;
+
+ assert_eq!(
+ items.len(),
+ 12,
+ "Should return all 12 items with large limit"
+ );
+
+ Ok(())
+}
+
+/// Standalone items (no project) are correctly returned with project_id = None.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_standalone_items_have_no_project(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::UpdatedAt, ()),
+ )
+ .await?;
+
+ let items_map: std::collections::HashMap<Uuid, &SoupItem> =
+ items.iter().map(|i| (i.id(), i)).collect();
+
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_STANDALONE)], SoupItem::Document);
+ assert_eq!(
+ doc.project_id, None,
+ "Standalone doc should have no project"
+ );
+ assert_eq!(doc.name, "Doc Standalone");
+
+ let chat = unwrap_enum!(items_map[&uuid(EX_CHAT_STANDALONE)], SoupItem::Chat);
+ assert_eq!(
+ chat.project_id, None,
+ "Standalone chat should have no project"
+ );
+ assert_eq!(chat.name, "Chat Standalone");
+
+ Ok(())
+}
+
+/// Documents in projects should carry the correct project_id, and projects
+/// in the hierarchy should carry the correct parent_id.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_hierarchy_project_ids(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::UpdatedAt, ()),
+ )
+ .await?;
+
+ let items_map: std::collections::HashMap<Uuid, &SoupItem> =
+ items.iter().map(|i| (i.id(), i)).collect();
+
+ // doc-in-deep should reference project-deep
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_DEEP)], SoupItem::Document);
+ assert_eq!(doc.project_id, Some(uuid(EX_PROJECT_DEEP)));
+
+ // doc-in-mid should reference project-mid
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_MID)], SoupItem::Document);
+ assert_eq!(doc.project_id, Some(uuid(EX_PROJECT_MID)));
+
+ // project-deep should have parent_id = project-mid
+ let proj = unwrap_enum!(items_map[&uuid(EX_PROJECT_DEEP)], SoupItem::Project);
+ assert_eq!(proj.parent_id, Some(uuid(EX_PROJECT_MID)));
+
+ // project-mid should have parent_id = project-root
+ let proj = unwrap_enum!(items_map[&uuid(EX_PROJECT_MID)], SoupItem::Project);
+ assert_eq!(proj.parent_id, Some(uuid(EX_PROJECT_ROOT)));
+
+ // project-root should have parent_id = None
+ let proj = unwrap_enum!(items_map[&uuid(EX_PROJECT_ROOT)], SoupItem::Project);
+ assert_eq!(proj.parent_id, None);
+
+ Ok(())
+}
+
+/// Items correctly report their viewed_at from UserHistory.
+/// Items without history should have viewed_at = None.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_viewed_at_values(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::UpdatedAt, ()),
+ )
+ .await?;
+
+ let items_map: std::collections::HashMap<Uuid, &SoupItem> =
+ items.iter().map(|i| (i.id(), i)).collect();
+
+ // Items WITH history should have Some(viewed_at)
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_MID)], SoupItem::Document);
+ assert!(
+ doc.viewed_at.is_some(),
+ "doc-in-mid has history and should have viewed_at"
+ );
+
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_ROOT)], SoupItem::Document);
+ assert!(
+ doc.viewed_at.is_some(),
+ "doc-in-root has history and should have viewed_at"
+ );
+
+ // Items WITHOUT history should have None
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_DEEP)], SoupItem::Document);
+ assert!(
+ doc.viewed_at.is_none(),
+ "doc-in-deep has no history and should have viewed_at=None"
+ );
+
+ let chat = unwrap_enum!(items_map[&uuid(EX_CHAT_STANDALONE)], SoupItem::Chat);
+ assert!(
+ chat.viewed_at.is_none(),
+ "chat-standalone has no history and should have viewed_at=None"
+ );
+
+ let proj = unwrap_enum!(items_map[&uuid(EX_PROJECT_MID)], SoupItem::Project);
+ assert!(
+ proj.viewed_at.is_none(),
+ "project-mid has no history and should have viewed_at=None"
+ );
+
+ Ok(())
+}
+
+/// Documents should carry their file_type and sha from the latest DocumentInstance.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_document_fields(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::UpdatedAt, ()),
+ )
+ .await?;
+
+ let items_map: std::collections::HashMap<Uuid, &SoupItem> =
+ items.iter().map(|i| (i.id(), i)).collect();
+
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_ROOT)], SoupItem::Document);
+ assert_eq!(doc.file_type.as_deref(), Some("pdf"));
+ assert_eq!(doc.sha.as_deref(), Some("sha-root"));
+ assert_eq!(doc.name, "Doc In Root");
+
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_MID)], SoupItem::Document);
+ assert_eq!(doc.file_type.as_deref(), Some("docx"));
+ assert_eq!(doc.sha.as_deref(), Some("sha-mid"));
+
+ let doc = unwrap_enum!(items_map[&uuid(EX_DOC_STANDALONE)], SoupItem::Document);
+ assert_eq!(doc.file_type.as_deref(), Some("txt"));
+ assert_eq!(doc.sha.as_deref(), Some("sha-standalone"));
+
+ Ok(())
+}
+
+/// All returned items should have the correct entity type variant.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("expanded_cursor_soup_exhaustive")
+ )
+)]
+async fn test_exhaustive_entity_type_counts(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let items = expanded_generic_cursor_soup(
+ &pool,
+ user_id.copied(),
+ 50,
+ Query::Sort(SimpleSortMethod::UpdatedAt, ()),
+ )
+ .await?;
+
+ let mut doc_count = 0;
+ let mut chat_count = 0;
+ let mut project_count = 0;
+
+ for item in &items {
+ match item {
+ SoupItem::Document(_) => doc_count += 1,
+ SoupItem::Chat(_) => chat_count += 1,
+ SoupItem::Project(_) => project_count += 1,
+ _ => panic!("Unexpected entity type"),
+ }
+ }
+
+ assert_eq!(doc_count, 7, "Should have 7 documents");
+ assert_eq!(chat_count, 2, "Should have 2 chats");
+ assert_eq!(project_count, 3, "Should have 3 projects");
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_cursor.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_cursor.rs
index f878a30ef8..d0864b4bbe 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_cursor.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_cursor.rs
@@ -191,7 +191,7 @@ pub async fn unexpanded_generic_cursor_soup(
FROM Combined
WHERE ($4::timestamptz IS NULL)
OR ("sort_ts!", "id!") < ($4, $5)
- ORDER BY "sort_ts!" DESC, "updated_at!" DESC
+ ORDER BY "sort_ts!" DESC, "id!" DESC
LIMIT $3
"#,
user_id.as_ref(), // $1
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs
index e5e954565d..cfadade422 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs
@@ -18,6 +18,7 @@ use uuid::Uuid;
/// be included in the results unless the user has been explicitly granted permissions on them.
/// This ensures that only directly authorized items are returned, not those with implicit
/// (inherited) access. Results are sorted to match the input entity order.
+#[tracing::instrument(err, skip(db, entities))]
pub async fn unexpanded_soup_by_ids<'a>(
db: &PgPool,
user_id: MacroUserIdStr<'_>,