补齐相关日志日志
This commit is contained in:
@@ -76,6 +76,8 @@ func (s *NotificationService) Read(ctx context.Context, userID int64, request *d
|
||||
if isNotFound(err) {
|
||||
return nil, errcode.NotificationNotFound
|
||||
}
|
||||
slog.ErrorContext(ctx, "read notification: query notification failed",
|
||||
"notification_uuid", request.NotificationUUID, "user_id", userID, "error", err)
|
||||
return nil, errcode.DatabaseError
|
||||
}
|
||||
if n.UserID != userID {
|
||||
@@ -93,6 +95,8 @@ func (s *NotificationService) Read(ctx context.Context, userID int64, request *d
|
||||
|
||||
// 条件标记已读(仅未读 -> 已读),防并发重复标记。
|
||||
if _, err := s.notificationDao.NotificationUpdateReadByUUIDIfUnread(ctx, request.NotificationUUID); err != nil {
|
||||
slog.ErrorContext(ctx, "mark notification read failed",
|
||||
"notification_uuid", request.NotificationUUID, "user_id", userID, "error", err)
|
||||
return nil, errcode.DatabaseError
|
||||
}
|
||||
// 无论本次是否真的标记成功,都按 DB 重新统计并回填缓存:
|
||||
@@ -127,8 +131,11 @@ func (s *NotificationService) unreadCount(ctx context.Context, userID int64) (in
|
||||
slog.WarnContext(ctx, "count unread from db failed, fallback to redis",
|
||||
"user_id", userID, "error", err)
|
||||
return rcnt, nil
|
||||
} else {
|
||||
slog.ErrorContext(ctx, "count unread failed: db and redis both unavailable",
|
||||
"user_id", userID, "db_error", err, "redis_error", rerr)
|
||||
return 0, errcode.DatabaseError
|
||||
}
|
||||
return 0, errcode.DatabaseError
|
||||
}
|
||||
if serr := redisdao.NotificationUnreadSet(ctx, userID, cnt); serr != nil {
|
||||
slog.WarnContext(ctx, "backfill notification unread cache failed",
|
||||
@@ -167,6 +174,7 @@ func sendNotification(ctx context.Context, recipientUserID, senderID int64, msgT
|
||||
return
|
||||
}
|
||||
if _, err := redisdao.NotificationUnreadIncr(ctx, recipientUserID); err != nil {
|
||||
slog.ErrorContext(ctx, "notification unread incr failed", "user_id", recipientUserID, "error", err)
|
||||
// 未读数是 best-effort 缓存:失败不影响通知已落库,级别与「通知创建失败」保持一致。
|
||||
slog.WarnContext(ctx, "notification unread incr failed", "user_id", recipientUserID, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user