refactor: shorten model and table prefixes

This commit is contained in:
2026-07-23 14:30:17 +08:00
parent 6e7be2f3a4
commit 0ca2898ac0
71 changed files with 707 additions and 638 deletions

View File

@@ -45,7 +45,7 @@ func (g *Gateway) SaveUserKey(userID uint, provider string, apiKey string) error
if err != nil {
return err
}
key := models.SenlinAgentAIKey{UserID: userID, Provider: provider, EncryptedAPIKey: encrypted}
key := models.SaAIKey{UserID: userID, Provider: provider, EncryptedAPIKey: encrypted}
return models.DBService.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "user_id"}},
DoUpdates: clause.AssignmentColumns([]string{"provider", "encrypted_api_key", "updated_at"}),
@@ -53,7 +53,7 @@ func (g *Gateway) SaveUserKey(userID uint, provider string, apiKey string) error
}
func (g *Gateway) SelectKey(userID uint) (SelectedKey, error) {
var userKey models.SenlinAgentAIKey
var userKey models.SaAIKey
err := models.DBService.Where("user_id = ?", userID).First(&userKey).Error
if err == nil {
selected := SelectedKey{Provider: userKey.Provider, KeyType: "user"}
@@ -77,7 +77,7 @@ func (g *Gateway) RecordCall(database *gorm.DB, userID uint, provider string, us
if database == nil {
database = models.DBService
}
return database.Create(&models.SenlinAgentAICallLog{
return database.Create(&models.SaAICallLog{
UserID: userID,
Provider: provider,
UsedKeyType: usedKeyType,
@@ -98,17 +98,17 @@ func (g *Gateway) ReserveRateLimit(userID uint, action string, limit int, window
currentTime = g.now().UTC()
}
windowStart := currentTime.Truncate(window)
bucket := models.SenlinAgentAIRateBucket{
bucket := models.SaAIRateBucket{
UserID: userID, Action: action, WindowStart: windowStart, Count: 1,
}
result := models.DBService.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "user_id"}, {Name: "action"}, {Name: "window_start"}},
DoUpdates: clause.Assignments(map[string]any{
"count": gorm.Expr("senlin_agent_ai_rate_buckets.count + 1"),
"count": gorm.Expr("sa_ai_rate_buckets.count + 1"),
"updated_at": currentTime,
}),
Where: clause.Where{Exprs: []clause.Expression{
clause.Lt{Column: clause.Column{Table: "senlin_agent_ai_rate_buckets", Name: "count"}, Value: limit},
clause.Lt{Column: clause.Column{Table: "sa_ai_rate_buckets", Name: "count"}, Value: limit},
}},
}).Create(&bucket)
if result.Error != nil {