-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: Updated Learning Assistant History payload to return in ascending order #129
Changes from all commits
cc51613
2f93c7e
726bfda
4e1ac79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,6 +217,10 @@ def get_message_history(courserun_key, user, message_count): | |
|
||
Returns a number of messages equal to the message_count value. | ||
""" | ||
message_history = LearningAssistantMessage.objects.filter( | ||
course_id=courserun_key, user=user).order_by('-created')[:message_count] | ||
# Explanation over the double reverse: This fetches the last message_count elements ordered by creating order DESC. | ||
# Slicing the list in the model is an equivalent of adding LIMIT on the query. | ||
# The result is the last chat messages for that user and course but in inversed order, so in order to flip them | ||
# its first turn into a list and then reversed. | ||
message_history = list(LearningAssistantMessage.objects.filter( | ||
course_id=courserun_key, user=user).order_by('-created')[:message_count])[::-1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can get the same affect by doing order_by('created'). Right now you're still sorting twice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed offline and the alternative would be less performant. I've added a comment with a justification on this. |
||
return message_history |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you include a changelog entry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one already: https://github.com/edx/learning-assistant/pull/129/files#diff-2c623f3c6a917be56c59d43279244996836262cb1e12d9d0786c9c49eef6b43c