fix(option): 配置项为空字符串时按空集合处理,消除 option 同步噪声日志#18
Merged
Conversation
当 DB 中某个 JSON 类型的 option(如 GroupGroupRatio、ModelRatio、PayMethods 等) 被清空为 "",定时 SyncOptions -> updateOptionMap 会对空串做 json.Unmarshal, 每个同步周期(默认 60s)刷一条: [SYS] failed to update option map: unexpected end of JSON input 统一在各 Update*ByJSONString 入口及 types.LoadFromJsonString/WithCallback 中 将「空字符串/纯空白」视为「空集合」直接返回 nil,不再 unmarshal。空配置语义 本就等价于空 map/空数组,行为不变,只是消除噪声日志。 覆盖: - types/rw_map.go: 覆盖全部 9 个 ratio 配置 + GroupGroupRatio - Chats / AutoGroups / TopupGroupRatio / ModelRequestRateLimitGroup / UserUsableGroups / PayMethods 新增 types/rw_map_empty_test.go 验证空串/空白/合法 JSON 三种输入。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
线上单实例排查时发现日志每 60s(SyncOptions 周期)刷一条:
定位为:DB 中某个 JSON 类型的 option 被清空成
"",定时SyncOptions → loadOptionsFromDatabase → updateOptionMap对空串做json.Unmarshal,触发unexpected end of JSON input。本次现网实际是GroupGroupRatio为空(已在 DB 侧改为{}临时止血),但同类风险存在于所有「可被前端清空」的 JSON 配置项。改动
统一把「空字符串/纯空白」视为「空集合」,直接返回
nil,不再 unmarshal。空配置语义本就等价于空 map / 空数组,行为不变,仅消除噪声日志,并避免该项在内存中保持上一轮旧值。集中点 + 散点覆盖:
types/rw_map.go(LoadFromJsonString/LoadFromJsonStringWithCallback)ModelRatio/GroupRatio/GroupGroupRatio/CompletionRatio/ModelPrice/CacheRatio/CreateCacheRatio/ImageRatio/AudioRatio/AudioCompletionRatiosetting/chat.goChatssetting/auto_group.goAutoGroupscommon/topup-ratio.goTopupGroupRatiosetting/rate_limit.goModelRequestRateLimitGroupsetting/user_usable_group.goUserUsableGroupssetting/operation_setting/payment_setting_old.goPayMethods测试
新增
types/rw_map_empty_test.go:空串 / 纯空白 / 合法 JSON 三类输入。备注
encoding/jsonvscommon.*的调用方式(保持 surgical,未顺带重构)。