mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: sort child chats newest-first and prepend on creation (#24524)
GetChildChatsByParentIDs sorted created_at ASC, but the cache helper appended new children to the end. On refetch the API and cache agreed on oldest-first, putting the just-created child at the bottom. Users expect newest first, matching the root-chat sidebar convention. - SQL: change child sort to created_at DESC, id DESC. - Cache: prepend instead of append in addChildToParentInCache (renamed from appendChildToParentInCache to avoid leaking position semantics). - Test: update ordering assertion to expect newest-first. Refs #24404
This commit is contained in:
@@ -6881,8 +6881,8 @@ WHERE
|
||||
ELSE chats.archived = $2 :: boolean
|
||||
END
|
||||
ORDER BY
|
||||
chats.created_at ASC,
|
||||
chats.id ASC
|
||||
chats.created_at DESC,
|
||||
chats.id DESC
|
||||
`
|
||||
|
||||
type GetChildChatsByParentIDsParams struct {
|
||||
|
||||
@@ -418,8 +418,8 @@ WHERE
|
||||
ELSE chats.archived = sqlc.narg('archived') :: boolean
|
||||
END
|
||||
ORDER BY
|
||||
chats.created_at ASC,
|
||||
chats.id ASC;
|
||||
chats.created_at DESC,
|
||||
chats.id DESC;
|
||||
|
||||
-- name: InsertChat :one
|
||||
INSERT INTO chats (
|
||||
|
||||
@@ -1333,10 +1333,10 @@ func TestListChats(t *testing.T) {
|
||||
}
|
||||
require.Len(t, parent.Children, 2, "parent should embed 2 children")
|
||||
|
||||
// Children should be ordered by created_at ASC.
|
||||
// Children are ordered by created_at DESC (newest first).
|
||||
childIDs := []uuid.UUID{parent.Children[0].ID, parent.Children[1].ID}
|
||||
require.Equal(t, child1.ID, childIDs[0])
|
||||
require.Equal(t, child2.ID, childIDs[1])
|
||||
require.Equal(t, child2.ID, childIDs[0])
|
||||
require.Equal(t, child1.ID, childIDs[1])
|
||||
|
||||
// Verify each child has correct parent/root references.
|
||||
for _, child := range parent.Children {
|
||||
|
||||
Reference in New Issue
Block a user