wood chen 9f51ac602e 实现内存缓存机制,优化数据库查询性能
- 新增内存缓存接口和实现,支持设置过期时间
- 在数据库初始化时创建全局缓存实例
- 为模型类型、提供商和价格查询添加缓存层
- 实现定期缓存常用数据的后台任务
- 优化数据库查询,减少重复查询和不必要的数据库访问
- 为价格查询添加索引,提高查询效率
2025-03-07 00:28:36 +08:00

40 lines
2.1 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
type Price struct {
ID uint `json:"id" gorm:"primaryKey"`
Model string `json:"model" gorm:"not null;index:idx_model_channel"`
ModelType string `json:"model_type" gorm:"not null;index:idx_model_type"` // text2text, text2image, etc.
BillingType string `json:"billing_type" gorm:"not null"` // tokens or times
ChannelType uint `json:"channel_type" gorm:"not null;index:idx_model_channel"`
Currency string `json:"currency" gorm:"not null"` // USD or CNY
InputPrice float64 `json:"input_price" gorm:"not null"`
OutputPrice float64 `json:"output_price" gorm:"not null"`
PriceSource string `json:"price_source" gorm:"not null"`
Status string `json:"status" gorm:"not null;default:pending;index:idx_status"` // pending, approved, rejected
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime;index:idx_created_at"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
CreatedBy string `json:"created_by" gorm:"not null"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
// 临时字段,用于存储待审核的更新
TempModel *string `json:"temp_model,omitempty" gorm:"column:temp_model"`
TempModelType *string `json:"temp_model_type,omitempty" gorm:"column:temp_model_type"`
TempBillingType *string `json:"temp_billing_type,omitempty" gorm:"column:temp_billing_type"`
TempChannelType *uint `json:"temp_channel_type,omitempty" gorm:"column:temp_channel_type"`
TempCurrency *string `json:"temp_currency,omitempty" gorm:"column:temp_currency"`
TempInputPrice *float64 `json:"temp_input_price,omitempty" gorm:"column:temp_input_price"`
TempOutputPrice *float64 `json:"temp_output_price,omitempty" gorm:"column:temp_output_price"`
TempPriceSource *string `json:"temp_price_source,omitempty" gorm:"column:temp_price_source"`
UpdatedBy *string `json:"updated_by,omitempty" gorm:"column:updated_by"`
}
// TableName 指定表名
func (Price) TableName() string {
return "price"
}