feat(chat): implement sequence pre-allocation, versioned sync, and push worker
Introduce several performance and synchronization enhancements: - Implement `SeqBufferManager` to allow sequence number pre-allocation via Redis Lua scripts, reducing atomic increment overhead. - Add `PushWorker` to handle asynchronous message pushing using Redis Streams. - Implement incremental conversation synchronization via `ConversationVersionLog` to allow clients to fetch only recent changes. - Add support for Gzip compression in WebSocket communications to reduce bandwidth usage. - Update dependency injection and configuration to support these new components.
This commit is contained in:
@@ -585,6 +585,37 @@ func (h *MessageHandler) HandleGetSyncData(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// HandleGetSyncByVersion 增量同步:按版本号获取会话变更
|
||||
// GET /api/v1/conversations/sync?version=0&limit=100
|
||||
func (h *MessageHandler) HandleGetSyncByVersion(c *gin.Context) {
|
||||
userID := c.GetString("user_id")
|
||||
if userID == "" {
|
||||
response.Unauthorized(c, "")
|
||||
return
|
||||
}
|
||||
|
||||
versionStr := c.DefaultQuery("version", "0")
|
||||
sinceVersion, err := strconv.ParseInt(versionStr, 10, 64)
|
||||
if err != nil || sinceVersion < 0 {
|
||||
response.BadRequest(c, "invalid version parameter")
|
||||
return
|
||||
}
|
||||
|
||||
limitStr := c.DefaultQuery("limit", "100")
|
||||
limit, err := strconv.Atoi(limitStr)
|
||||
if err != nil || limit < 1 {
|
||||
limit = 100
|
||||
}
|
||||
|
||||
result, err := h.chatService.GetSyncByVersion(c.Request.Context(), userID, sinceVersion, limit)
|
||||
if err != nil {
|
||||
response.InternalServerError(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, result)
|
||||
}
|
||||
|
||||
// GetConversationUnreadCount 获取单个会话的未读数
|
||||
// GET /api/conversations/:id/unread/count
|
||||
func (h *MessageHandler) GetConversationUnreadCount(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user