refactor(cache): remove deprecated unread count methods and keys
All checks were successful
Build Backend / build (push) Successful in 2m5s
Build Backend / build-docker (push) Successful in 1m19s

Clean up the codebase by removing unused and deprecated unread count
functionality in `ConversationCache` and associated Redis key
generators. This follows the transition to sequence-based unread
calculation.

- Remove `IncrementUnread`, `ClearUnread`, `GetUnreadCountFromHash`,
  `GetAllUnreadCounts`, and `GetTotalUnread` from `ConversationCache`.
- Remove `PrefixUnreadHash` and `PrefixUnreadTotal` constants and
  `UnreadHashKey`/`UnreadTotalKey` helper functions.
- Remove unused `isValidContentType` helper in `MessageHandler`.
This commit is contained in:
2026-05-12 18:26:31 +08:00
parent 8d7e8c427b
commit 06db8e36e4
3 changed files with 1 additions and 53 deletions

View File

@@ -692,36 +692,6 @@ func (c *ConversationCache) ComputeAllUnreadCount(ctx context.Context, userID st
return total, nil return total, nil
} }
// IncrementUnread 递增用户在某会话的未读数(已废弃:改用 seq 算术计算)
// Deprecated: Unread count is now computed via arithmetic (maxSeq - readSeq).
func (c *ConversationCache) IncrementUnread(ctx context.Context, userID, convID string) error {
return nil
}
// ClearUnread 清零用户在某会话的未读数(已废弃:改用 seq 算术计算)
// Deprecated: No longer needed. Unread is computed from seq arithmetic.
func (c *ConversationCache) ClearUnread(ctx context.Context, userID, convID string) error {
return nil
}
// GetUnreadCountFromHash 从 Redis Hash 获取单个会话未读数(已废弃)
// Deprecated: Use ComputeUnreadCount instead.
func (c *ConversationCache) GetUnreadCountFromHash(ctx context.Context, userID, convID string) (int64, error) {
return 0, ErrKeyNotFound
}
// GetAllUnreadCounts 从 Redis Hash 获取用户所有会话的未读数(已废弃)
// Deprecated: Use ComputeAllUnreadCount instead.
func (c *ConversationCache) GetAllUnreadCounts(ctx context.Context, userID string) (map[string]int64, error) {
return nil, ErrKeyNotFound
}
// GetTotalUnread 从 Redis 获取用户总未读数(已废弃)
// Deprecated: Use ComputeAllUnreadCount instead.
func (c *ConversationCache) GetTotalUnread(ctx context.Context, userID string) (int64, error) {
return 0, ErrKeyNotFound
}
// GetNextSeq 获取会话的下一个 seq 值(原子递增) // GetNextSeq 获取会话的下一个 seq 值(原子递增)
// 使用 Redis INCR 实现,首次调用时从 DB 初始化并补齐差值 // 使用 Redis INCR 实现,首次调用时从 DB 初始化并补齐差值
func (c *ConversationCache) GetNextSeq(ctx context.Context, convID string) (int64, error) { func (c *ConversationCache) GetNextSeq(ctx context.Context, convID string) (int64, error) {

View File

@@ -26,8 +26,6 @@ const (
PrefixUnreadSystem = "unread:system" PrefixUnreadSystem = "unread:system"
PrefixUnreadConversation = "unread:conversation" PrefixUnreadConversation = "unread:conversation"
PrefixUnreadDetail = "unread:detail" PrefixUnreadDetail = "unread:detail"
PrefixUnreadHash = "unread:hash"
PrefixUnreadTotal = "unread:total"
// 已读位置相关OpenIM 风格:缓存 hasReadSeq用于 O(1) 未读数计算) // 已读位置相关OpenIM 风格:缓存 hasReadSeq用于 O(1) 未读数计算)
PrefixUserReadSeq = "user_read_seq" PrefixUserReadSeq = "user_read_seq"
@@ -123,16 +121,6 @@ func UnreadDetailKey(userID, conversationID string) string {
return fmt.Sprintf("%s:%s:%s", PrefixUnreadDetail, userID, conversationID) return fmt.Sprintf("%s:%s:%s", PrefixUnreadDetail, userID, conversationID)
} }
// UnreadHashKey 生成用户未读数 Hash 缓存键
func UnreadHashKey(userID string) string {
return fmt.Sprintf("%s:%s", PrefixUnreadHash, userID)
}
// UnreadTotalKey 生成用户总未读数计数器键
func UnreadTotalKey(userID string) string {
return fmt.Sprintf("%s:%s", PrefixUnreadTotal, userID)
}
// UserInfoKey 生成用户信息缓存键 // UserInfoKey 生成用户信息缓存键
func UserInfoKey(userID string) string { func UserInfoKey(userID string) string {
return fmt.Sprintf("%s:%s", PrefixUserInfo, userID) return fmt.Sprintf("%s:%s", PrefixUserInfo, userID)

View File

@@ -653,16 +653,6 @@ func (h *MessageHandler) DeleteMessage(c *gin.Context) {
response.SuccessWithMessage(c, "message deleted", nil) response.SuccessWithMessage(c, "message deleted", nil)
} }
// 辅助函数:验证内容类型
func isValidContentType(contentType model.ContentType) bool {
switch contentType {
case model.ContentTypeText, model.ContentTypeImage, model.ContentTypeVideo, model.ContentTypeAudio, model.ContentTypeFile:
return true
default:
return false
}
}
// 辅助函数:获取会话参与者信息 // 辅助函数:获取会话参与者信息
func (h *MessageHandler) getConversationParticipants(ctx context.Context, conversationID string, currentUserID string) ([]*model.User, error) { func (h *MessageHandler) getConversationParticipants(ctx context.Context, conversationID string, currentUserID string) ([]*model.User, error) {
// 从repository获取参与者列表 // 从repository获取参与者列表