Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Sort conversations by updated_at desc #7348

Merged
merged 11 commits into from
Aug 20, 2024

Conversation

KinWang130
Copy link
Contributor

@KinWang130 KinWang130 commented Aug 16, 2024

Checklist:

Important

Please review the checklist below before submitting your pull request.

  • I have performed a self-review of my own code
  • I ran dev/pr(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

Description

In the process of using dify for conversations, the historical conversation records are always sorted in descending order according to the time of session creation. Normally, they should be sorted according to the latest time of conversation messages.
My optimization is to modify the updated_at of the conversation during the conversation, and sort the conversation list in descending order based on the updated_at. This way, users can see the latest list of session messages.

Fixes #7338

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update, included: Dify Document
  • Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement
  • Dependency upgrade

Testing Instructions

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Initiate a new conversation, with the new conversation at the forefront
  • The conversation list is sorted based on the latest time of the conversation content

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. 💪 enhancement New feature or request labels Aug 16, 2024
@crazywoola crazywoola requested a review from laipz8200 August 16, 2024 08:51
@KinWang130 KinWang130 changed the title The conversation list is sorted by the latest news feat: The conversation list is sorted by the latest message Aug 16, 2024
@laipz8200
Copy link
Member

I think sorting by creation time is reasonable because it ensures the relative order of items in the list remains unchanged. Do you have a more compelling argument for sorting by update time?

@KinWang130
Copy link
Contributor Author

I think sorting by creation time is reasonable because it ensures the relative order of items in the list remains unchanged. Do you have a more compelling argument for sorting by update time?

Of course, sorting by creation time can ensure that the relative order remains unchanged, but in most conversational applications such as GPT, WeChat, Telegram, etc., conversations are always sorted by the latest conversation messages. My optimization reasons are as follows:

  1. Updated_at is always unchanged. When a new message is generated in a conversation or the conversation name is modified, updated_at should be updated, otherwise it is meaningless
  2. Each conversation may generate a theme, and when users generate new messages in each conversation, I believe they want the conversation to be prioritized, which is very user-friendly
    What's your opinion?

@laipz8200
Copy link
Member

I think sorting by creation time is reasonable because it ensures the relative order of items in the list remains unchanged. Do you have a more compelling argument for sorting by update time?

Of course, sorting by creation time can ensure that the relative order remains unchanged, but in most conversational applications such as GPT, WeChat, Telegram, etc., conversations are always sorted by the latest conversation messages. My optimization reasons are as follows:

1. Updated_at is always unchanged. When a new message is generated in a conversation or the conversation name is modified, updated_at should be updated, otherwise it is meaningless

2. Each conversation may generate a theme, and when users generate new messages in each conversation, I believe they want the conversation to be prioritized, which is very user-friendly
   What's your opinion?

I think it would be great to support both options. How about we add a sort_by parameter to the API? That way, we could pass sort_by=-updated_at to sort by updated_at in descending order.

@leslie2046
Copy link
Contributor

+1
#7338
I think the conversation list on the left side of the webui should be sorted by 'updated_at'
And the log list in the console should also be sorted by updated_at. When we check the logs every day, we hope to only look at the current day's logs without having to repeatedly review the sessions we have already seen yesterday.

@KinWang130
Copy link
Contributor Author

KinWang130 commented Aug 17, 2024

I think sorting by creation time is reasonable because it ensures the relative order of items in the list remains unchanged. Do you have a more compelling argument for sorting by update time?

Of course, sorting by creation time can ensure that the relative order remains unchanged, but in most conversational applications such as GPT, WeChat, Telegram, etc., conversations are always sorted by the latest conversation messages. My optimization reasons are as follows:

1. Updated_at is always unchanged. When a new message is generated in a conversation or the conversation name is modified, updated_at should be updated, otherwise it is meaningless

2. Each conversation may generate a theme, and when users generate new messages in each conversation, I believe they want the conversation to be prioritized, which is very user-friendly
   What's your opinion?

I think it would be great to support both options. How about we add a sort_by parameter to the API? That way, we could pass sort_by=-updated_at to sort by updated_at in descending order.

Of course, the code I have submitted has already solved the two issues mentioned above.And it has been tested and the results are correct

  1. Update the updated_at field of the session when generating new messages or renaming the session name
  2. Retrieve the conversation list in descending order based on updated_at

@laipz8200
Copy link
Member

Hi @KinWang130! Apologies for the lack of clarity earlier. We would like to support the option to specify the sorting method in the web service API. Instead of directly changing the current sorting method, we aim to allow users to choose their preferred sorting method by adding a button in the frontend. Would you be willing to implement this feature?

…rameter values: 'creatd_at', '- creatd_at', 'updated_at', '- updated_at'
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Aug 19, 2024
@KinWang130
Copy link
Contributor Author

KinWang130 commented Aug 19, 2024

Hi @KinWang130! Apologies for the lack of clarity earlier. We would like to support the option to specify the sorting method in the web service API. Instead of directly changing the current sorting method, we aim to allow users to choose their preferred sorting method by adding a button in the frontend. Would you be willing to implement this feature?

I am honored to assist you in implementing this feature. My newly submitted code now supports sort_by parameter sorting, including web and API interfaces. The parameter examples are as follows:
created_at: Ascending by creation time
-created_at: Sort by creation time in descending order
updated_at: Ascending by update time
-updated_at: Sort by update time in descending order
Because I am a backend developer, I am sorry that I cannot provide frontend code implementation. in addition
My personal suggestion is not to provide a sorting button on the conversation list page to affect its appearance. You can refer to the chat app on the market. If necessary, the sort_by parameter can be modified through the application API to achieve custom sorting of conversations

…rameter values: 'creatd_at', '- creatd_at', 'updated_at', '- updated_at'
@laipz8200
Copy link
Member

@KinWang130 Thank you very much for your contribution! We plan to add sorting options on the logs page and use the default order on the chat page. Due to the need for design and front-end development, the merging of this PR might be slightly delayed.

Additionally, please check the CI errors.

…rameter values: 'creatd_at', '- creatd_at', 'updated_at', '- updated_at'
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Aug 19, 2024
@laipz8200
Copy link
Member

You can run dev/reformat to fix the most lint errors automatically.

@leslie2046
Copy link
Contributor

@laipz8200
#7338
My issue will be resolved if we can sort by create_at or update_at in logs page ,thank you!

…rameter values: 'creatd_at', '- creatd_at', 'updated_at', '- updated_at'
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Aug 19, 2024
@KinWang130
Copy link
Contributor Author

You can run dev/reformat to fix the most lint errors automatically.

OK,Thanks

crazywoola
crazywoola previously approved these changes Aug 19, 2024
Copy link
Member

@crazywoola crazywoola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 19, 2024
@KinWang130 KinWang130 requested a review from laipz8200 August 19, 2024 13:17
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Aug 20, 2024
@laipz8200 laipz8200 changed the title feat: The conversation list is sorted by the latest message feat: Sort conversations by updated_at desc Aug 20, 2024
Copy link
Member

@laipz8200 laipz8200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@laipz8200 laipz8200 merged commit e35e251 into langgenius:main Aug 20, 2024
6 checks passed
ZuzooVn added a commit to ZuzooVn/dify that referenced this pull request Aug 20, 2024
@ZuzooVn ZuzooVn mentioned this pull request Aug 20, 2024
4 tasks
@KinWang130 KinWang130 deleted the dev-pr branch August 20, 2024 12:00
@KinWang130 KinWang130 restored the dev-pr branch August 20, 2024 12:16
@KinWang130 KinWang130 deleted the dev-pr branch August 20, 2024 12:16
crazywoola pushed a commit that referenced this pull request Aug 21, 2024
cuiks pushed a commit to cuiks/dify that referenced this pull request Sep 2, 2024
cuiks pushed a commit to cuiks/dify that referenced this pull request Sep 2, 2024
ZuzooVn added a commit to ZuzooVn/dify that referenced this pull request Sep 6, 2024
idonotknow pushed a commit to AceDataCloud/Dify that referenced this pull request Nov 16, 2024
idonotknow pushed a commit to AceDataCloud/Dify that referenced this pull request Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add filter by update time of conversations
5 participants