perf(chat): 分页客服会话并拆分统计查询
This commit is contained in:
@@ -45,9 +45,9 @@ func (r *Repository) conversationQuery(ctx context.Context, principal Principal)
|
||||
SELECT COUNT(1)
|
||||
FROM chat_messages AS cm
|
||||
WHERE cm.conversation_id = c.id
|
||||
AND cm.sender_type <> 'system'
|
||||
AND NOT (cm.sender_type = ? AND cm.sender_id = ?)
|
||||
AND (cp.last_read_at IS NULL OR cm.created_at > cp.last_read_at)
|
||||
AND cm.sender_type <> 'system'
|
||||
AND NOT (cm.sender_type = ? AND cm.sender_id = ?)
|
||||
AND (cp.last_read_at IS NULL OR cm.created_at > cp.last_read_at)
|
||||
) AS unread_count`, principal.Type, principal.ID).
|
||||
Joins("JOIN chat_participants AS cp ON cp.conversation_id = c.id").
|
||||
Where("cp.participant_type = ? AND cp.participant_id = ?", principal.Type, principal.ID)
|
||||
@@ -184,11 +184,12 @@ func (r *Repository) toMessageDTOs(ctx context.Context, principal Principal, row
|
||||
SenderAvatar: avatar,
|
||||
IsSelf: isSelf,
|
||||
// 仅对自己发出的消息计算已读:是否已被所有其他参与者读取。
|
||||
IsRead: isSelf && messageReadByOthers(readParticipants[row.ConversationID], row),
|
||||
ContentType: row.ContentType,
|
||||
Content: row.Content,
|
||||
AttachmentURLS: decodeStringList(row.AttachmentURLS),
|
||||
CreatedAt: row.CreatedAt,
|
||||
IsRead: isSelf && messageReadByOthers(readParticipants[row.ConversationID], row),
|
||||
ContentType: row.ContentType,
|
||||
Content: row.Content,
|
||||
AttachmentURLS: decodeStringList(row.AttachmentURLS),
|
||||
AdminAttentionType: row.AdminAttentionType,
|
||||
CreatedAt: row.CreatedAt,
|
||||
})
|
||||
}
|
||||
return items, nil
|
||||
|
||||
Reference in New Issue
Block a user