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.
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type PostReferenceStatus string
|
|
|
|
const (
|
|
PostRefActive PostReferenceStatus = "active"
|
|
PostRefDead PostReferenceStatus = "dead"
|
|
PostRefHidden PostReferenceStatus = "hidden"
|
|
)
|
|
|
|
type PostReference struct {
|
|
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
|
|
SourcePostID string `json:"source_post_id" gorm:"type:varchar(36);not null;uniqueIndex:uq_source_target;index:idx_source_post"`
|
|
TargetPostID string `json:"target_post_id" gorm:"type:varchar(36);not null;uniqueIndex:uq_source_target;index:idx_target_post;index:idx_target_status"`
|
|
Status PostReferenceStatus `json:"status" gorm:"type:varchar(20);default:active;index:idx_target_status"`
|
|
ClickCount int `json:"click_count" gorm:"default:0"`
|
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime:false"`
|
|
|
|
SourcePost *Post `json:"source_post,omitempty" gorm:"foreignKey:SourcePostID"`
|
|
TargetPost *Post `json:"target_post,omitempty" gorm:"foreignKey:TargetPostID"`
|
|
}
|
|
|
|
func (pr *PostReference) BeforeCreate(tx *gorm.DB) error {
|
|
SetUUIDIfEmpty(&pr.ID)
|
|
return nil
|
|
}
|
|
|
|
func (PostReference) TableName() string {
|
|
return "post_references"
|
|
}
|