Clean backend debug logging and standardize error reporting.
This removes verbose trace output in handlers/services and keeps only actionable error-level logs.
This commit is contained in:
@@ -2,7 +2,6 @@ package repository
|
||||
|
||||
import (
|
||||
"carrot_bbs/internal/model"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -40,8 +39,6 @@ func (r *MessageRepository) GetConversation(id string) (*model.Conversation, err
|
||||
func (r *MessageRepository) GetOrCreatePrivateConversation(user1ID, user2ID string) (*model.Conversation, error) {
|
||||
var conv model.Conversation
|
||||
|
||||
fmt.Printf("[DEBUG] GetOrCreatePrivateConversation: user1ID=%s, user2ID=%s\n", user1ID, user2ID)
|
||||
|
||||
// 查找两个用户共同参与的私聊会话
|
||||
err := r.db.Table("conversations c").
|
||||
Joins("INNER JOIN conversation_participants cp1 ON c.id = cp1.conversation_id AND cp1.user_id = ?", user1ID).
|
||||
@@ -53,7 +50,6 @@ func (r *MessageRepository) GetOrCreatePrivateConversation(user1ID, user2ID stri
|
||||
_ = r.db.Model(&model.ConversationParticipant{}).
|
||||
Where("conversation_id = ? AND user_id IN ?", conv.ID, []string{user1ID, user2ID}).
|
||||
Update("hidden_at", nil).Error
|
||||
fmt.Printf("[DEBUG] GetOrCreatePrivateConversation: found existing conversation, ID=%s\n", conv.ID)
|
||||
return &conv, nil
|
||||
}
|
||||
|
||||
@@ -62,7 +58,6 @@ func (r *MessageRepository) GetOrCreatePrivateConversation(user1ID, user2ID stri
|
||||
}
|
||||
|
||||
// 没找到会话,创建新会话
|
||||
fmt.Printf("[DEBUG] GetOrCreatePrivateConversation: no existing conversation found, creating new one\n")
|
||||
conv = model.Conversation{
|
||||
Type: model.ConversationTypePrivate,
|
||||
}
|
||||
@@ -85,10 +80,6 @@ func (r *MessageRepository) GetOrCreatePrivateConversation(user1ID, user2ID stri
|
||||
return nil
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
fmt.Printf("[DEBUG] GetOrCreatePrivateConversation: created new conversation, ID=%s\n", conv.ID)
|
||||
}
|
||||
|
||||
return &conv, err
|
||||
}
|
||||
|
||||
@@ -153,20 +144,10 @@ func (r *MessageRepository) GetMessagesAfterSeq(conversationID string, afterSeq
|
||||
// GetMessagesBeforeSeq 获取指定seq之前的历史消息(用于下拉加载更多)
|
||||
func (r *MessageRepository) GetMessagesBeforeSeq(conversationID string, beforeSeq int64, limit int) ([]*model.Message, error) {
|
||||
var messages []*model.Message
|
||||
fmt.Printf("[DEBUG] GetMessagesBeforeSeq: conversationID=%s, beforeSeq=%d, limit=%d\n", conversationID, beforeSeq, limit)
|
||||
err := r.db.Where("conversation_id = ? AND seq < ?", conversationID, beforeSeq).
|
||||
Order("seq DESC"). // 降序获取最新消息在前
|
||||
Limit(limit).
|
||||
Find(&messages).Error
|
||||
fmt.Printf("[DEBUG] GetMessagesBeforeSeq: found %d messages, seq range: ", len(messages))
|
||||
for i, m := range messages {
|
||||
if i < 5 || i >= len(messages)-2 {
|
||||
fmt.Printf("%d ", m.Seq)
|
||||
} else if i == 5 {
|
||||
fmt.Printf("... ")
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
// 反转回正序
|
||||
for i, j := 0, len(messages)-1; i < j; i, j = i+1, j-1 {
|
||||
messages[i], messages[j] = messages[j], messages[i]
|
||||
|
||||
Reference in New Issue
Block a user