Fix conversation sorting and pagination (#6014)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
tofarr 2025-01-03 12:35:20 -07:00 committed by GitHub
parent 1ddf398a81
commit a6d392322a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -68,7 +68,6 @@ class FileConversationStore(ConversationStore):
num_conversations = len(conversation_ids)
start = page_id_to_offset(page_id)
end = min(limit + start, num_conversations)
conversation_ids = conversation_ids[start:end]
conversations = []
for conversation_id in conversation_ids:
try:
@ -79,6 +78,8 @@ class FileConversationStore(ConversationStore):
exc_info=True,
stack_info=True,
)
conversations.sort(key=_sort_key, reverse=True)
conversations = conversations[start:end]
next_page_id = offset_to_page_id(end, end < num_conversations)
return ConversationMetadataResultSet(conversations, next_page_id)
@ -92,3 +93,10 @@ class FileConversationStore(ConversationStore):
async def get_instance(cls, config: AppConfig, token: str | None):
file_store = get_file_store(config.file_store, config.file_store_path)
return FileConversationStore(file_store)
def _sort_key(conversation: ConversationMetadata) -> str:
last_updated_at = conversation.last_updated_at
if last_updated_at:
return last_updated_at.isoformat() # YYYY-MM-DDTHH:MM:SS for sorting
return ''