lab2: fix review — cache consistency, readiness, timeouts, uuid validation, tuple index
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-10 01:14:56 +03:00
parent a327909856
commit 40f260612f
21 changed files with 185 additions and 189 deletions
+4 -9
View File
@@ -28,12 +28,12 @@ func (r *ChatRepository) Create(ctx context.Context, chat *domain.Chat) error {
}
defer func() { _ = tx.Rollback(ctx) }()
const insertChat = `INSERT INTO chats (id, title, created_at) VALUES ($1, $2, $3)`
const insertChat = `INSERT INTO chats (id, title, created_at) VALUES ($1::uuid, $2, $3)`
if _, err := tx.Exec(ctx, insertChat, chat.ID, chat.Title, chat.CreatedAt); err != nil {
return fmt.Errorf("insert chat: %w", err)
}
const insertMember = `INSERT INTO chat_members (chat_id, user_id) VALUES ($1, $2)`
const insertMember = `INSERT INTO chat_members (chat_id, user_id) VALUES ($1::uuid, $2::uuid)`
for _, uid := range chat.MemberIDs {
if _, err := tx.Exec(ctx, insertMember, chat.ID, uid); err != nil {
return fmt.Errorf("insert member %s: %w", uid, err)
@@ -104,7 +104,7 @@ func (r *ChatRepository) ListByMember(ctx context.Context, userID string, cursor
FROM chats c
JOIN chat_members m ON m.chat_id = c.id
WHERE m.user_id = $1::uuid
AND (c.created_at > $2 OR (c.created_at = $2 AND c.id > $3::uuid))
AND (c.created_at, c.id) > ($2::timestamptz, $3::uuid)
ORDER BY c.created_at, c.id
LIMIT $4
`
@@ -132,12 +132,7 @@ func (r *ChatRepository) ListByMember(ctx context.Context, userID string, cursor
return chats, nil
}
const qMembers = `
SELECT chat_id, user_id
FROM chat_members
WHERE chat_id = ANY($1::uuid[])
ORDER BY chat_id, user_id
`
const qMembers = `SELECT chat_id, user_id FROM chat_members WHERE chat_id = ANY($1::uuid[]) ORDER BY chat_id, user_id`
memberRows, err := r.pool.Query(ctx, qMembers, chatIDs)
if err != nil {
return nil, fmt.Errorf("list members: %w", err)