-
Notifications
You must be signed in to change notification settings - Fork 2.8k
perf: Optimize the convert_value method and reuse it
#5166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,14 @@ def support(self, node_id, fields: List[str], source_value, compare, target_valu | |
| return True | ||
|
|
||
| def compare(self, source_value, compare, target_value): | ||
| target_value = str(target_value) | ||
|
|
||
| if isinstance(source_value, str): | ||
| return str(target_value) not in source_value | ||
| return target_value not in source_value | ||
| elif isinstance(source_value, list): | ||
| return not any([str(item) == str(target_value) for item in source_value]) | ||
| for item in source_value: | ||
| if str(item) == target_value: | ||
| return False | ||
| return True | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上:为 list 时,性能优化了下。 |
||
| else: | ||
| return str(target_value) not in str(source_value) | ||
| return target_value not in str(source_value) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| """ | ||
| import hashlib | ||
| import io | ||
| import json | ||
| import mimetypes | ||
| import pickle | ||
| import random | ||
|
|
@@ -360,3 +361,31 @@ def is_valid_uuid(uuid_string): | |
| return str(uuid_obj) == uuid_string | ||
| except ValueError: | ||
| return False | ||
|
|
||
| def common_convert_value(_type, value): | ||
| if value is None: | ||
| return None | ||
|
|
||
| if _type == 'int': | ||
| return int(value) | ||
| if _type == 'boolean': | ||
| if isinstance(value, str) and value.lower() in ('false', '0', '[]', ''): | ||
| return False | ||
| return bool(value) | ||
| if _type == 'float': | ||
| return float(value) | ||
| if _type == 'dict': | ||
| if isinstance(value, dict): | ||
| return value | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 当 |
||
| v = json.loads(value) | ||
| if isinstance(v, dict): | ||
| return v | ||
| raise Exception(_('type error')) | ||
| if _type == 'array': | ||
| if isinstance(value, list): | ||
| return value | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 当 |
||
| v = json.loads(value) | ||
| if isinstance(v, list): | ||
| return v | ||
| raise Exception(_('type error')) | ||
| return value | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为 list 时,性能优化了下。