Skip to content

Commit

Permalink
Update chat session query to use LEFT JOIN and order by latest messag…
Browse files Browse the repository at this point in the history
…e time and session ID.
  • Loading branch information
swuecho committed Nov 27, 2024
1 parent 653087f commit c82909e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions api/sqlc/queries/chat_session.sql
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ returning *;
-- name: GetChatSessionsByUserID :many
SELECT cs.*
FROM chat_session cs
JOIN (
LEFT JOIN (
SELECT chat_session_uuid, MAX(created_at) AS latest_message_time
FROM chat_message
GROUP BY chat_session_uuid
) cm ON cs.uuid = cm.chat_session_uuid
WHERE cs.user_id = $1 AND cs.active = true
ORDER BY cm.latest_message_time DESC;
ORDER BY
cm.latest_message_time DESC,
cs.id DESC;


-- SELECT cs.*
Expand Down
6 changes: 4 additions & 2 deletions api/sqlc_queries/chat_session.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c82909e

Please sign in to comment.