fix(chat): 优化后台限流与 SSE 日志

This commit is contained in:
yml2213
2026-08-25 16:20:58 +08:00
parent 417f7398e4
commit 8f6356a3d7
11 changed files with 344 additions and 47 deletions
+10 -1
View File
@@ -108,16 +108,25 @@ func isPaymentNotifyPath(path string) bool {
}
// shouldSkipHTTPLog 判断是否为无需记录的普通请求。
func shouldSkipHTTPLog(_, _ string, status int, latencyMs float64) bool {
func shouldSkipHTTPLog(path, route string, status int, latencyMs float64) bool {
if status >= 500 || status == http.StatusTooManyRequests {
return false
}
// SSE 的请求耗时就是连接存活时间,由 chathub 单独记录连接生命周期。
if isChatSSEPath(path, route) {
return true
}
if latencyMs >= slowRequestThresholdMs {
return false
}
return true
}
func isChatSSEPath(path, route string) bool {
return path == "/api/chats/events" || path == "/api/admin/chats/events" ||
route == "/api/chats/events" || route == "/api/admin/chats/events"
}
func meaningfulAuthFailure(c *gin.Context) bool {
value, ok := c.Get(ContextAuthFailureReason)
if !ok {