Commit ff4b5b3f by creamlike1024

feat: improve ratio update

parent 2875dbba
...@@ -619,6 +619,7 @@ func getHardcodedCompletionModelRatio(name string) (float64, bool) { ...@@ -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 { ...@@ -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 { ...@@ -698,14 +700,16 @@ func AudioRatio2JSONString() string {
} }
func UpdateAudioRatioByJSONString(jsonStr string) error { func UpdateAudioRatioByJSONString(jsonStr string) error {
tmp := make(map[string]float64)
if err := common.Unmarshal([]byte(jsonStr), &tmp); err != nil {
return err
}
audioRatioMapMutex.Lock() audioRatioMapMutex.Lock()
defer audioRatioMapMutex.Unlock() audioRatioMap = tmp
audioRatioMap = make(map[string]float64) audioRatioMapMutex.Unlock()
err := common.Unmarshal([]byte(jsonStr), &audioRatioMap)
if err == nil {
InvalidateExposedDataCache() InvalidateExposedDataCache()
} return nil
return err
} }
func GetAudioRatioCopy() map[string]float64 { func GetAudioRatioCopy() map[string]float64 {
...@@ -729,14 +733,15 @@ func AudioCompletionRatio2JSONString() string { ...@@ -729,14 +733,15 @@ func AudioCompletionRatio2JSONString() string {
} }
func UpdateAudioCompletionRatioByJSONString(jsonStr string) error { func UpdateAudioCompletionRatioByJSONString(jsonStr string) error {
tmp := make(map[string]float64)
if err := common.Unmarshal([]byte(jsonStr), &tmp); err != nil {
return err
}
audioCompletionRatioMapMutex.Lock() audioCompletionRatioMapMutex.Lock()
defer audioCompletionRatioMapMutex.Unlock() audioCompletionRatioMap = tmp
audioCompletionRatioMap = make(map[string]float64) audioCompletionRatioMapMutex.Unlock()
err := common.Unmarshal([]byte(jsonStr), &audioCompletionRatioMap)
if err == nil {
InvalidateExposedDataCache() InvalidateExposedDataCache()
} return nil
return err
} }
func GetAudioCompletionRatioCopy() map[string]float64 { func GetAudioCompletionRatioCopy() map[string]float64 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment