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:
@@ -306,8 +306,6 @@ func (s *UserService) GetFollowing(ctx context.Context, userID string, page, pag
|
||||
|
||||
// FollowUser 关注用户
|
||||
func (s *UserService) FollowUser(ctx context.Context, followerID, followeeID string) error {
|
||||
fmt.Printf("[DEBUG] FollowUser called: followerID=%s, followeeID=%s\n", followerID, followeeID)
|
||||
|
||||
blocked, err := s.userRepo.IsBlockedEitherDirection(followerID, followeeID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -319,11 +317,9 @@ func (s *UserService) FollowUser(ctx context.Context, followerID, followeeID str
|
||||
// 检查是否已经关注
|
||||
isFollowing, err := s.userRepo.IsFollowing(followerID, followeeID)
|
||||
if err != nil {
|
||||
fmt.Printf("[DEBUG] Error checking existing follow: %v\n", err)
|
||||
return err
|
||||
}
|
||||
if isFollowing {
|
||||
fmt.Printf("[DEBUG] Already following, skip creation\n")
|
||||
return nil // 已经关注,直接返回成功
|
||||
}
|
||||
|
||||
@@ -335,23 +331,18 @@ func (s *UserService) FollowUser(ctx context.Context, followerID, followeeID str
|
||||
|
||||
err = s.userRepo.CreateFollow(follow)
|
||||
if err != nil {
|
||||
fmt.Printf("[DEBUG] CreateFollow error: %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("[DEBUG] Follow record created successfully\n")
|
||||
|
||||
// 刷新关注者的关注数(通过实际计数,更可靠)
|
||||
err = s.userRepo.RefreshFollowingCount(followerID)
|
||||
if err != nil {
|
||||
fmt.Printf("[DEBUG] Error refreshing following count: %v\n", err)
|
||||
// 不回滚,计数可以通过其他方式修复
|
||||
}
|
||||
|
||||
// 刷新被关注者的粉丝数(通过实际计数,更可靠)
|
||||
err = s.userRepo.RefreshFollowersCount(followeeID)
|
||||
if err != nil {
|
||||
fmt.Printf("[DEBUG] Error refreshing followers count: %v\n", err)
|
||||
// 不回滚,计数可以通过其他方式修复
|
||||
}
|
||||
|
||||
@@ -359,56 +350,38 @@ func (s *UserService) FollowUser(ctx context.Context, followerID, followeeID str
|
||||
if s.systemMessageService != nil {
|
||||
// 异步发送通知,不阻塞主流程
|
||||
go func() {
|
||||
notifyErr := s.systemMessageService.SendFollowNotification(context.Background(), followeeID, followerID)
|
||||
if notifyErr != nil {
|
||||
fmt.Printf("[DEBUG] Error sending follow notification: %v\n", notifyErr)
|
||||
} else {
|
||||
fmt.Printf("[DEBUG] Follow notification sent successfully to %s\n", followeeID)
|
||||
}
|
||||
_ = s.systemMessageService.SendFollowNotification(context.Background(), followeeID, followerID)
|
||||
}()
|
||||
}
|
||||
|
||||
fmt.Printf("[DEBUG] FollowUser completed: followerID=%s, followeeID=%s\n", followerID, followeeID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnfollowUser 取消关注用户
|
||||
func (s *UserService) UnfollowUser(ctx context.Context, followerID, followeeID string) error {
|
||||
fmt.Printf("[DEBUG] UnfollowUser called: followerID=%s, followeeID=%s\n", followerID, followeeID)
|
||||
|
||||
// 检查是否已经关注
|
||||
isFollowing, err := s.userRepo.IsFollowing(followerID, followeeID)
|
||||
if err != nil {
|
||||
fmt.Printf("[DEBUG] Error checking existing follow: %v\n", err)
|
||||
return err
|
||||
}
|
||||
if !isFollowing {
|
||||
fmt.Printf("[DEBUG] Not following, skip deletion\n")
|
||||
return nil // 没有关注,直接返回成功
|
||||
}
|
||||
|
||||
// 删除关注关系
|
||||
err = s.userRepo.DeleteFollow(followerID, followeeID)
|
||||
if err != nil {
|
||||
fmt.Printf("[DEBUG] DeleteFollow error: %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("[DEBUG] Follow record deleted successfully\n")
|
||||
|
||||
// 刷新关注者的关注数(通过实际计数,更可靠)
|
||||
err = s.userRepo.RefreshFollowingCount(followerID)
|
||||
if err != nil {
|
||||
fmt.Printf("[DEBUG] Error refreshing following count: %v\n", err)
|
||||
}
|
||||
|
||||
// 刷新被关注者的粉丝数(通过实际计数,更可靠)
|
||||
err = s.userRepo.RefreshFollowersCount(followeeID)
|
||||
if err != nil {
|
||||
fmt.Printf("[DEBUG] Error refreshing followers count: %v\n", err)
|
||||
}
|
||||
|
||||
fmt.Printf("[DEBUG] UnfollowUser completed: followerID=%s, followeeID=%s\n", followerID, followeeID)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user