From 152825758bd439c32cb9c5f4fc2af8f9ef789f12 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 17 Jul 2025 15:31:36 +0000 Subject: [PATCH 1/3] Filter out stale asset import chats from GET /chats and /logs endpoints - Add subqueries to count user messages (non-null request_message) and total messages per chat - Filter out chats with zero user messages AND only one total message - This excludes auto-generated asset import chats that users never interacted with - Applied same filtering logic to both list_chats_handler.rs and list_logs_handler.rs Fixes BUS-1415 Co-Authored-By: Dallin Bentley --- .../handlers/src/chats/list_chats_handler.rs | 19 +++++++++++++++++-- .../handlers/src/logs/list_logs_handler.rs | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/apps/api/libs/handlers/src/chats/list_chats_handler.rs b/apps/api/libs/handlers/src/chats/list_chats_handler.rs index 5701d6192..22d1c7f08 100644 --- a/apps/api/libs/handlers/src/chats/list_chats_handler.rs +++ b/apps/api/libs/handlers/src/chats/list_chats_handler.rs @@ -78,7 +78,7 @@ pub async fn list_chats_handler( request: ListChatsRequest, user: &AuthenticatedUser, ) -> Result> { - use database::schema::{asset_permissions, chats, users}; + use database::schema::{asset_permissions, chats, messages, users}; let mut conn = get_pg_pool().get().await?; @@ -101,11 +101,26 @@ pub async fn list_chats_handler( Vec::new() // If admin view, we'll show all chats anyway }; + let user_message_count = messages::table + .filter(messages::chat_id.eq(chats::id)) + .filter(messages::request_message.is_not_null()) + .filter(messages::deleted_at.is_null()) + .count(); + + let total_message_count = messages::table + .filter(messages::chat_id.eq(chats::id)) + .filter(messages::deleted_at.is_null()) + .count(); + // Start building the query let mut query = chats::table .inner_join(users::table.on(chats::created_by.eq(users::id))) .filter(chats::deleted_at.is_null()) .filter(chats::title.ne("")) // Filter out empty titles + .filter( + user_message_count.gt(0) + .or(total_message_count.gt(1)) + ) .into_boxed(); // Add user filter if not admin view @@ -173,4 +188,4 @@ pub async fn list_chats_handler( }; Ok(items) -} \ No newline at end of file +} diff --git a/apps/api/libs/handlers/src/logs/list_logs_handler.rs b/apps/api/libs/handlers/src/logs/list_logs_handler.rs index 4ce45bf8e..507dccafa 100644 --- a/apps/api/libs/handlers/src/logs/list_logs_handler.rs +++ b/apps/api/libs/handlers/src/logs/list_logs_handler.rs @@ -69,10 +69,21 @@ pub async fn list_logs_handler( request: ListLogsRequest, organization_id: Uuid, ) -> Result { - use database::schema::{chats, users}; + use database::schema::{chats, messages, users}; let mut conn = get_pg_pool().get().await?; + let user_message_count = messages::table + .filter(messages::chat_id.eq(chats::id)) + .filter(messages::request_message.is_not_null()) + .filter(messages::deleted_at.is_null()) + .count(); + + let total_message_count = messages::table + .filter(messages::chat_id.eq(chats::id)) + .filter(messages::deleted_at.is_null()) + .count(); + // Start building the query let mut query = chats::table .inner_join(users::table.on(chats::created_by.eq(users::id))) @@ -80,6 +91,10 @@ pub async fn list_logs_handler( .filter(chats::organization_id.eq(organization_id)) .filter(chats::title.ne("")) // Filter out empty titles .filter(chats::title.ne(" ")) // Filter out single space + .filter( + user_message_count.gt(0) + .or(total_message_count.gt(1)) + ) .into_boxed(); // Calculate offset based on page number From 9e461f9948c3b313db3c91b310f53b0a90cc00ea Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 17 Jul 2025 15:42:19 +0000 Subject: [PATCH 2/3] Fix Docker context paths in GitHub workflows - change ./api to ./apps/api Co-Authored-By: Dallin Bentley --- .github/workflows/cli-testing.yml | 4 ++-- .github/workflows/docker-release.yml | 6 +++--- .github/workflows/web-e2e-tests-optimized.yml | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cli-testing.yml b/.github/workflows/cli-testing.yml index 7608eabff..b5a603d7b 100644 --- a/.github/workflows/cli-testing.yml +++ b/.github/workflows/cli-testing.yml @@ -31,8 +31,8 @@ jobs: - name: Build and Load API Docker Image uses: useblacksmith/build-push-action@v1 with: - context: ./api - file: ./api/Dockerfile + context: ./apps/api + file: ./apps/api/Dockerfile push: false # Do not push, load locally for service container load: true # Load the image into the runner's Docker daemon tags: local-api-test:latest # Tag for the service definition diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 85f346aea..315a04697 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -103,8 +103,8 @@ jobs: - name: Build and push API image uses: useblacksmith/build-push-action@v1 with: - context: ./api - file: ./api/Dockerfile + context: ./apps/api + file: ./apps/api/Dockerfile push: true platforms: ${{ matrix.docker_platform }} tags: | @@ -199,4 +199,4 @@ jobs: else echo "Failed to set package $ORG_NAME/${{ env.WEB_IMAGE_NAME }} visibility to public. HTTP Status: $RESPONSE_CODE" # Optionally, fail the step: exit 1 - fi \ No newline at end of file + fi diff --git a/.github/workflows/web-e2e-tests-optimized.yml b/.github/workflows/web-e2e-tests-optimized.yml index cfdeea73c..e7885d6f7 100644 --- a/.github/workflows/web-e2e-tests-optimized.yml +++ b/.github/workflows/web-e2e-tests-optimized.yml @@ -69,8 +69,8 @@ jobs: - name: Build & Load API Docker Image uses: useblacksmith/build-push-action@v1 with: - context: ./api - file: ./api/Dockerfile + context: ./apps/api + file: ./apps/api/Dockerfile push: false load: true tags: local-api-test:latest @@ -199,4 +199,4 @@ jobs: if: always() run: | docker stop local-api - docker rm local-api \ No newline at end of file + docker rm local-api From ea083784bcf8a44b6e9f2b476c72ece4d369162a Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 17 Jul 2025 16:21:13 +0000 Subject: [PATCH 3/3] Fix Diesel subquery compilation errors - use exists() and raw SQL for message filtering Co-Authored-By: Dallin Bentley --- .../handlers/src/chats/list_chats_handler.rs | 23 ++++++++----------- .../handlers/src/logs/list_logs_handler.rs | 23 ++++++++----------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/apps/api/libs/handlers/src/chats/list_chats_handler.rs b/apps/api/libs/handlers/src/chats/list_chats_handler.rs index 22d1c7f08..a0fdd824d 100644 --- a/apps/api/libs/handlers/src/chats/list_chats_handler.rs +++ b/apps/api/libs/handlers/src/chats/list_chats_handler.rs @@ -101,25 +101,22 @@ pub async fn list_chats_handler( Vec::new() // If admin view, we'll show all chats anyway }; - let user_message_count = messages::table - .filter(messages::chat_id.eq(chats::id)) - .filter(messages::request_message.is_not_null()) - .filter(messages::deleted_at.is_null()) - .count(); - - let total_message_count = messages::table - .filter(messages::chat_id.eq(chats::id)) - .filter(messages::deleted_at.is_null()) - .count(); - // Start building the query let mut query = chats::table .inner_join(users::table.on(chats::created_by.eq(users::id))) .filter(chats::deleted_at.is_null()) .filter(chats::title.ne("")) // Filter out empty titles .filter( - user_message_count.gt(0) - .or(total_message_count.gt(1)) + diesel::dsl::exists( + messages::table + .filter(messages::chat_id.eq(chats::id)) + .filter(messages::request_message.is_not_null()) + .filter(messages::deleted_at.is_null()) + ).or( + diesel::dsl::sql::( + "(SELECT COUNT(*) FROM messages WHERE messages.chat_id = chats.id AND messages.deleted_at IS NULL) > 1" + ) + ) ) .into_boxed(); diff --git a/apps/api/libs/handlers/src/logs/list_logs_handler.rs b/apps/api/libs/handlers/src/logs/list_logs_handler.rs index 507dccafa..09d65fabe 100644 --- a/apps/api/libs/handlers/src/logs/list_logs_handler.rs +++ b/apps/api/libs/handlers/src/logs/list_logs_handler.rs @@ -73,17 +73,6 @@ pub async fn list_logs_handler( let mut conn = get_pg_pool().get().await?; - let user_message_count = messages::table - .filter(messages::chat_id.eq(chats::id)) - .filter(messages::request_message.is_not_null()) - .filter(messages::deleted_at.is_null()) - .count(); - - let total_message_count = messages::table - .filter(messages::chat_id.eq(chats::id)) - .filter(messages::deleted_at.is_null()) - .count(); - // Start building the query let mut query = chats::table .inner_join(users::table.on(chats::created_by.eq(users::id))) @@ -92,8 +81,16 @@ pub async fn list_logs_handler( .filter(chats::title.ne("")) // Filter out empty titles .filter(chats::title.ne(" ")) // Filter out single space .filter( - user_message_count.gt(0) - .or(total_message_count.gt(1)) + diesel::dsl::exists( + messages::table + .filter(messages::chat_id.eq(chats::id)) + .filter(messages::request_message.is_not_null()) + .filter(messages::deleted_at.is_null()) + ).or( + diesel::dsl::sql::( + "(SELECT COUNT(*) FROM messages WHERE messages.chat_id = chats.id AND messages.deleted_at IS NULL) > 1" + ) + ) ) .into_boxed();