From f560a1fc96aa03b7b073092b1ae9268d8d7e9cb5 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Wed, 6 Nov 2024 18:00:46 -0800 Subject: [PATCH] fixed query history --- backend/ee/danswer/db/query_history.py | 2 +- backend/ee/danswer/db/usage_export.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/backend/ee/danswer/db/query_history.py b/backend/ee/danswer/db/query_history.py index 973f7cec6b2..0243d614e7f 100644 --- a/backend/ee/danswer/db/query_history.py +++ b/backend/ee/danswer/db/query_history.py @@ -30,7 +30,7 @@ def fetch_chat_sessions_eagerly_by_time( ] if initial_time: - filters.append(ChatSession.time_created < initial_time) + filters.append(ChatSession.time_created > initial_time) subquery = ( db_session.query(ChatSession.id, ChatSession.time_created) diff --git a/backend/ee/danswer/db/usage_export.py b/backend/ee/danswer/db/usage_export.py index 885116c5867..34d23db4cf0 100644 --- a/backend/ee/danswer/db/usage_export.py +++ b/backend/ee/danswer/db/usage_export.py @@ -21,7 +21,7 @@ def get_empty_chat_messages_entries__paginated( period: tuple[datetime, datetime], limit: int | None = 500, initial_time: datetime | None = None, -) -> list[ChatMessageSkeleton]: +) -> tuple[int, list[ChatMessageSkeleton]]: chat_sessions = fetch_chat_sessions_eagerly_by_time( start=period[0], end=period[1], @@ -53,8 +53,9 @@ def get_empty_chat_messages_entries__paginated( time_sent=message.time_sent, ) ) - - return message_skeletons + if len(chat_sessions) == 0: + return None, [] + return chat_sessions[0].time_created, message_skeletons def get_all_empty_chat_message_entries( @@ -65,22 +66,20 @@ def get_all_empty_chat_message_entries( ind = 0 while True: ind += 1 - print(ind) - print(initial_time) - message_skeletons = get_empty_chat_messages_entries__paginated( + + time_created, message_skeletons = get_empty_chat_messages_entries__paginated( db_session, period, initial_time=initial_time, ) - print("length", len(message_skeletons)) + if not message_skeletons: return yield message_skeletons # Update initial_time for the next iteration - last_message = message_skeletons[-1] - initial_time = last_message.time_sent + initial_time = time_created def get_all_usage_reports(db_session: Session) -> list[UsageReportMetadata]: