Backend - Add GetBoundChannelsByModelsMap to batch-fetch bound channels via a single JOIN (Distinct), compatible with SQLite/MySQL/PostgreSQL - Replace per-record enrichment with a single-pass enrichModels to avoid N+1 queries; compute unions for prefix/suffix/contains matches in memory - Change Model.QuotaType to QuotaTypes []int and expose quota_types in responses - Add GetModelQuotaTypes for cached O(1) lookups; exact models return a single-element array - Sort quota_types for stable output order - Remove unused code: GetModelByName, GetBoundChannels, GetBoundChannelsForModels, FindModelByNameWithRule, buildPrefixes, buildSuffixes - Clean up redundant comments, keeping concise and readable code Frontend - Models table: switch to quota_types, render multiple billing modes ([0], [1], [0,1], future values supported) - Pricing table: switch to quota_types; ratio display now checks quota_types.includes(0); array rendering for billing tags Compatibility - SQL uses standard JOIN/IN/Distinct; works across SQLite/MySQL/PostgreSQL - Lint passes; no DB schema changes (quota_types is a JSON response field only) Breaking Change - API field renamed: quota_type -> quota_types (array). Update clients accordingly.
32 lines
632 B
Go
32 lines
632 B
Go
package model
|
|
|
|
func GetModelEnableGroups(modelName string) []string {
|
|
// 确保缓存最新
|
|
GetPricing()
|
|
|
|
if modelName == "" {
|
|
return make([]string, 0)
|
|
}
|
|
|
|
modelEnableGroupsLock.RLock()
|
|
groups, ok := modelEnableGroups[modelName]
|
|
modelEnableGroupsLock.RUnlock()
|
|
if !ok {
|
|
return make([]string, 0)
|
|
}
|
|
return groups
|
|
}
|
|
|
|
// GetModelQuotaTypes 返回指定模型的计费类型集合(来自缓存)
|
|
func GetModelQuotaTypes(modelName string) []int {
|
|
GetPricing()
|
|
|
|
modelEnableGroupsLock.RLock()
|
|
quota, ok := modelQuotaTypeMap[modelName]
|
|
modelEnableGroupsLock.RUnlock()
|
|
if !ok {
|
|
return []int{}
|
|
}
|
|
return []int{quota}
|
|
}
|