perf: Optimize the convert_value method and reuse it#5166
perf: Optimize the convert_value method and reuse it#5166wangliang181230 wants to merge 5 commits into1Panel-dev:v2from
convert_value method and reuse it#5166Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
convert_value methodconvert_value method and reuse it
| return float(value) | ||
| if _type == 'dict': | ||
| if isinstance(value, dict): | ||
| return value |
There was a problem hiding this comment.
当 value 已经是 dict 时,直接 return,否则 json.loads(value) 会报错
| raise Exception(_('type error')) | ||
| if _type == 'array': | ||
| if isinstance(value, list): | ||
| return value |
There was a problem hiding this comment.
当 value 已经是 list 时,直接 return,否则 json.loads(value) 会报错
| for item in source_value: | ||
| if str(item) == target_value: | ||
| return True | ||
| return False |
There was a problem hiding this comment.
为 list 时,性能优化了下。
| for item in source_value: | ||
| if str(item) == target_value: | ||
| return False | ||
| return True |
There was a problem hiding this comment.
同上:为 list 时,性能优化了下。
What this PR does / why we need it?
Optimize the
convert_valuemethod and reuse itSummary of your change
优化
convert_value方法:_type为dict或array时,先判断 value 是否已经是该类型并直接return,避免报错。common.py中共用Please indicate you've done the following: