Merge pull request #529 from buster-so/devin/BUS-1415-1752766195

Filter out stale asset import chats from GET /chats and /logs endpoints
This commit is contained in:
dal 2025-07-17 09:24:33 -07:00 committed by GitHub
commit 3d6c7549bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 35 additions and 11 deletions

View File

@ -31,8 +31,8 @@ jobs:
- name: Build and Load API Docker Image - name: Build and Load API Docker Image
uses: useblacksmith/build-push-action@v1 uses: useblacksmith/build-push-action@v1
with: with:
context: ./api context: ./apps/api
file: ./api/Dockerfile file: ./apps/api/Dockerfile
push: false # Do not push, load locally for service container push: false # Do not push, load locally for service container
load: true # Load the image into the runner's Docker daemon load: true # Load the image into the runner's Docker daemon
tags: local-api-test:latest # Tag for the service definition tags: local-api-test:latest # Tag for the service definition

View File

@ -103,8 +103,8 @@ jobs:
- name: Build and push API image - name: Build and push API image
uses: useblacksmith/build-push-action@v1 uses: useblacksmith/build-push-action@v1
with: with:
context: ./api context: ./apps/api
file: ./api/Dockerfile file: ./apps/api/Dockerfile
push: true push: true
platforms: ${{ matrix.docker_platform }} platforms: ${{ matrix.docker_platform }}
tags: | tags: |
@ -199,4 +199,4 @@ jobs:
else else
echo "Failed to set package $ORG_NAME/${{ env.WEB_IMAGE_NAME }} visibility to public. HTTP Status: $RESPONSE_CODE" echo "Failed to set package $ORG_NAME/${{ env.WEB_IMAGE_NAME }} visibility to public. HTTP Status: $RESPONSE_CODE"
# Optionally, fail the step: exit 1 # Optionally, fail the step: exit 1
fi fi

View File

@ -69,8 +69,8 @@ jobs:
- name: Build & Load API Docker Image - name: Build & Load API Docker Image
uses: useblacksmith/build-push-action@v1 uses: useblacksmith/build-push-action@v1
with: with:
context: ./api context: ./apps/api
file: ./api/Dockerfile file: ./apps/api/Dockerfile
push: false push: false
load: true load: true
tags: local-api-test:latest tags: local-api-test:latest
@ -199,4 +199,4 @@ jobs:
if: always() if: always()
run: | run: |
docker stop local-api docker stop local-api
docker rm local-api docker rm local-api

View File

@ -78,7 +78,7 @@ pub async fn list_chats_handler(
request: ListChatsRequest, request: ListChatsRequest,
user: &AuthenticatedUser, user: &AuthenticatedUser,
) -> Result<Vec<ChatListItem>> { ) -> Result<Vec<ChatListItem>> {
use database::schema::{asset_permissions, chats, users}; use database::schema::{asset_permissions, chats, messages, users};
let mut conn = get_pg_pool().get().await?; let mut conn = get_pg_pool().get().await?;
@ -106,6 +106,18 @@ pub async fn list_chats_handler(
.inner_join(users::table.on(chats::created_by.eq(users::id))) .inner_join(users::table.on(chats::created_by.eq(users::id)))
.filter(chats::deleted_at.is_null()) .filter(chats::deleted_at.is_null())
.filter(chats::title.ne("")) // Filter out empty titles .filter(chats::title.ne("")) // Filter out empty titles
.filter(
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::<diesel::sql_types::Bool>(
"(SELECT COUNT(*) FROM messages WHERE messages.chat_id = chats.id AND messages.deleted_at IS NULL) > 1"
)
)
)
.into_boxed(); .into_boxed();
// Add user filter if not admin view // Add user filter if not admin view
@ -173,4 +185,4 @@ pub async fn list_chats_handler(
}; };
Ok(items) Ok(items)
} }

View File

@ -69,7 +69,7 @@ pub async fn list_logs_handler(
request: ListLogsRequest, request: ListLogsRequest,
organization_id: Uuid, organization_id: Uuid,
) -> Result<ListLogsResponse, anyhow::Error> { ) -> Result<ListLogsResponse, anyhow::Error> {
use database::schema::{chats, users}; use database::schema::{chats, messages, users};
let mut conn = get_pg_pool().get().await?; let mut conn = get_pg_pool().get().await?;
@ -80,6 +80,18 @@ pub async fn list_logs_handler(
.filter(chats::organization_id.eq(organization_id)) .filter(chats::organization_id.eq(organization_id))
.filter(chats::title.ne("")) // Filter out empty titles .filter(chats::title.ne("")) // Filter out empty titles
.filter(chats::title.ne(" ")) // Filter out single space .filter(chats::title.ne(" ")) // Filter out single space
.filter(
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::<diesel::sql_types::Bool>(
"(SELECT COUNT(*) FROM messages WHERE messages.chat_id = chats.id AND messages.deleted_at IS NULL) > 1"
)
)
)
.into_boxed(); .into_boxed();
// Calculate offset based on page number // Calculate offset based on page number