fix: harden controlled AI session consistency
This commit is contained in:
19
backend/internal/models/ai_rate_bucket.go
Normal file
19
backend/internal/models/ai_rate_bucket.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// SenlinAgentAIRateBucket 保存用户在固定窗口内已占用的 AI 请求配额。
|
||||
// 复合唯一键让单条 UPSERT 在数据库层完成跨进程并发仲裁。
|
||||
type SenlinAgentAIRateBucket struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
UserID uint `gorm:"not null;uniqueIndex:uidx_senlin_agent_ai_rate_bucket,priority:1"`
|
||||
Action string `gorm:"size:100;not null;uniqueIndex:uidx_senlin_agent_ai_rate_bucket,priority:2"`
|
||||
WindowStart time.Time `gorm:"not null;uniqueIndex:uidx_senlin_agent_ai_rate_bucket,priority:3"`
|
||||
Count int `gorm:"not null"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
func (SenlinAgentAIRateBucket) TableName() string {
|
||||
return "senlin_agent_ai_rate_buckets"
|
||||
}
|
||||
@@ -38,6 +38,7 @@ func AutoMigrate(database *gorm.DB) error {
|
||||
&SenlinAgentProjectEvent{},
|
||||
&SenlinAgentAIKey{},
|
||||
&SenlinAgentAICallLog{},
|
||||
&SenlinAgentAIRateBucket{},
|
||||
&SenlinAgentTaskShare{},
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user