refactor(cache): remove deprecated unread count methods and keys
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:
30
internal/cache/conversation_cache.go
vendored
30
internal/cache/conversation_cache.go
vendored
@@ -692,36 +692,6 @@ func (c *ConversationCache) ComputeAllUnreadCount(ctx context.Context, userID st
|
||||
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 值(原子递增)
|
||||
// 使用 Redis INCR 实现,首次调用时从 DB 初始化并补齐差值
|
||||
func (c *ConversationCache) GetNextSeq(ctx context.Context, convID string) (int64, error) {
|
||||
|
||||
12
internal/cache/keys.go
vendored
12
internal/cache/keys.go
vendored
@@ -26,8 +26,6 @@ const (
|
||||
PrefixUnreadSystem = "unread:system"
|
||||
PrefixUnreadConversation = "unread:conversation"
|
||||
PrefixUnreadDetail = "unread:detail"
|
||||
PrefixUnreadHash = "unread:hash"
|
||||
PrefixUnreadTotal = "unread:total"
|
||||
|
||||
// 已读位置相关(OpenIM 风格:缓存 hasReadSeq,用于 O(1) 未读数计算)
|
||||
PrefixUserReadSeq = "user_read_seq"
|
||||
@@ -123,16 +121,6 @@ func UnreadDetailKey(userID, conversationID string) string {
|
||||
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 生成用户信息缓存键
|
||||
func UserInfoKey(userID string) string {
|
||||
return fmt.Sprintf("%s:%s", PrefixUserInfo, userID)
|
||||
|
||||
@@ -653,16 +653,6 @@ func (h *MessageHandler) DeleteMessage(c *gin.Context) {
|
||||
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) {
|
||||
// 从repository获取参与者列表
|
||||
|
||||
Reference in New Issue
Block a user