mirror of https://github.com/buster-so/buster.git
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 <dallinbentley98@gmail.com>
This commit is contained in:
parent
bc1fbb0d7e
commit
152825758b
|
@ -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?;
|
||||||
|
|
||||||
|
@ -101,11 +101,26 @@ pub async fn list_chats_handler(
|
||||||
Vec::new() // If admin view, we'll show all chats anyway
|
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
|
// Start building the query
|
||||||
let mut query = chats::table
|
let mut query = chats::table
|
||||||
.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(
|
||||||
|
user_message_count.gt(0)
|
||||||
|
.or(total_message_count.gt(1))
|
||||||
|
)
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
// Add user filter if not admin view
|
// Add user filter if not admin view
|
||||||
|
|
|
@ -69,10 +69,21 @@ 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?;
|
||||||
|
|
||||||
|
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
|
// Start building the query
|
||||||
let mut query = chats::table
|
let mut query = chats::table
|
||||||
.inner_join(users::table.on(chats::created_by.eq(users::id)))
|
.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::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(
|
||||||
|
user_message_count.gt(0)
|
||||||
|
.or(total_message_count.gt(1))
|
||||||
|
)
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
// Calculate offset based on page number
|
// Calculate offset based on page number
|
||||||
|
|
Loading…
Reference in New Issue