Files
backend/internal/model/group.go
lan ee78071d4d
All checks were successful
Build Backend / build (push) Successful in 3m2s
Build Backend / build-docker (push) Successful in 2m44s
refactor: improve system stability, performance, and code structure
This commit introduces several architectural improvements and optimizations across the codebase:

- **Performance & Reliability**:
  - Implemented Redis pipelining in `ConversationCache.CacheMessage` to reduce network round-trips.
  - Added a circuit breaker to the JPush client to prevent cascading failures.
  - Introduced batch deletion and batch member addition capabilities in repositories.
  - Added message idempotency support using `client_msg_id` and a Redis-based cache.
  - Optimized WebSocket handling with connection limits (total and per-user) and improved error logging.

- **Code Refactoring**:
  - Refactored `Router` to use a `RouterDeps` struct, simplifying the constructor and improving maintainability.
  - Unified model ID generation logic using new `id_helper.go` (supporting UUID and Snowflake).
  - Standardized JSON serialization/deserialization in models using `json_helper.go`.
  - Refactored DTO conversion logic, specifically for `UserResponse` (using functional options) and `Report` responses.
  - Removed redundant/deprecated DTOs like `PostDetailResponse` and `TradeItemDetailResponse`.

- **Cache Improvements**:
  - Enhanced `LayeredCache` with `SetRaw` to avoid double-encoding when promoting values from Redis to local cache.
  - Added `DeleteBatch` support to the cache interface.

- **Other Changes**:
  - Cleaned up `config.go` by removing redundant default values and explicit environment variable overrides.
  - Improved WebSocket registration flow to handle connection limits gracefully.
2026-05-04 13:07:03 +08:00

49 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package model
import (
"strconv"
"time"
"gorm.io/gorm"
)
// JoinType 群组加入类型
type JoinType int
const (
JoinTypeAnyone JoinType = 0 // 允许任何人加入
JoinTypeApproval JoinType = 1 // 需要审批
JoinTypeForbidden JoinType = 2 // 不允许加入
)
// Group 群组模型
type Group struct {
ID string `gorm:"primaryKey;size:20" json:"id"`
Name string `gorm:"size:50;not null" json:"name"`
Avatar string `gorm:"size:512" json:"avatar"`
Description string `gorm:"size:500" json:"description"`
OwnerID string `gorm:"type:varchar(36);not null;index" json:"owner_id"`
MemberCount int `gorm:"default:0" json:"member_count"`
MaxMembers int `gorm:"default:500" json:"max_members"`
JoinType JoinType `gorm:"default:0" json:"join_type"` // 0:允许任何人加入 1:需要审批 2:不允许加入
MuteAll bool `gorm:"default:false" json:"mute_all"` // 全员禁言
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// BeforeCreate 创建前生成雪花算法ID
func (g *Group) BeforeCreate(tx *gorm.DB) error {
return SetSnowflakeStringID(&g.ID)
}
// GetIDInt 获取数字类型的ID用于比较
func (g *Group) GetIDInt() uint64 {
id, _ := strconv.ParseUint(g.ID, 10, 64)
return id
}
// TableName 指定表名
func (Group) TableName() string {
return "groups"
}