feat: improve ratio update

This commit is contained in:
creamlike1024
2025-08-30 23:53:46 +08:00
parent 2875dbba10
commit ff4b5b3fd2

View File

@@ -619,6 +619,7 @@ func getHardcodedCompletionModelRatio(name string) (float64, bool) {
func GetAudioRatio(name string) float64 { func GetAudioRatio(name string) float64 {
audioRatioMapMutex.RLock() audioRatioMapMutex.RLock()
defer audioRatioMapMutex.RUnlock() defer audioRatioMapMutex.RUnlock()
name = FormatMatchingModelName(name)
if ratio, ok := audioRatioMap[name]; ok { if ratio, ok := audioRatioMap[name]; ok {
return ratio return ratio
} }
@@ -628,6 +629,7 @@ func GetAudioRatio(name string) float64 {
func GetAudioCompletionRatio(name string) float64 { func GetAudioCompletionRatio(name string) float64 {
audioCompletionRatioMapMutex.RLock() audioCompletionRatioMapMutex.RLock()
defer audioCompletionRatioMapMutex.RUnlock() defer audioCompletionRatioMapMutex.RUnlock()
name = FormatMatchingModelName(name)
if ratio, ok := audioCompletionRatioMap[name]; ok { if ratio, ok := audioCompletionRatioMap[name]; ok {
return ratio return ratio
@@ -698,14 +700,16 @@ func AudioRatio2JSONString() string {
} }
func UpdateAudioRatioByJSONString(jsonStr string) error { func UpdateAudioRatioByJSONString(jsonStr string) error {
audioRatioMapMutex.Lock()
defer audioRatioMapMutex.Unlock() tmp := make(map[string]float64)
audioRatioMap = make(map[string]float64) if err := common.Unmarshal([]byte(jsonStr), &tmp); err != nil {
err := common.Unmarshal([]byte(jsonStr), &audioRatioMap) return err
if err == nil {
InvalidateExposedDataCache()
} }
return err audioRatioMapMutex.Lock()
audioRatioMap = tmp
audioRatioMapMutex.Unlock()
InvalidateExposedDataCache()
return nil
} }
func GetAudioRatioCopy() map[string]float64 { func GetAudioRatioCopy() map[string]float64 {
@@ -729,14 +733,15 @@ func AudioCompletionRatio2JSONString() string {
} }
func UpdateAudioCompletionRatioByJSONString(jsonStr string) error { func UpdateAudioCompletionRatioByJSONString(jsonStr string) error {
audioCompletionRatioMapMutex.Lock() tmp := make(map[string]float64)
defer audioCompletionRatioMapMutex.Unlock() if err := common.Unmarshal([]byte(jsonStr), &tmp); err != nil {
audioCompletionRatioMap = make(map[string]float64) return err
err := common.Unmarshal([]byte(jsonStr), &audioCompletionRatioMap)
if err == nil {
InvalidateExposedDataCache()
} }
return err audioCompletionRatioMapMutex.Lock()
audioCompletionRatioMap = tmp
audioCompletionRatioMapMutex.Unlock()
InvalidateExposedDataCache()
return nil
} }
func GetAudioCompletionRatioCopy() map[string]float64 { func GetAudioCompletionRatioCopy() map[string]float64 {