Skip to content

Commit

Permalink
chore: Added comment on get_message_history() explaining the double i…
Browse files Browse the repository at this point in the history
…nversion.
  • Loading branch information
rijuma committed Nov 12, 2024
1 parent 726bfda commit 4e1ac79
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions learning_assistant/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ def get_message_history(courserun_key, user, message_count):
Returns a number of messages equal to the message_count value.
"""
# 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]
return message_history

0 comments on commit 4e1ac79

Please sign in to comment.