refactor: drop redundant len(tag_ids)==0 check in get_target_ids_by_tag_ids (#38447)

This commit is contained in:
i晟 2026-07-06 12:35:58 +08:00 committed by GitHub
parent 94c0967e30
commit 586c8de1a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 5 deletions

View File

@ -61,10 +61,17 @@ _sensitive_word_avoidance_adapter: TypeAdapter[SensitiveWordAvoidanceConfig] = T
def _normalize_raw(raw: Any) -> Any:
if isinstance(raw, dict):
if raw.get("enabled") is None:
enabled = raw.get("enabled")
if enabled is None:
raw = {**raw, "enabled": False}
elif raw.get("enabled") is True and raw.get("config") is None:
raw = {**raw, "config": {}}
elif enabled is True:
if raw.get("config") is None:
raw = {**raw, "config": {}}
else:
# enabled is False or any falsy value —
# drop extra fields (type, config) so they don't
# violate SensitiveWordAvoidanceDisabledConfig.extra="forbid"
raw = {"enabled": False}
return raw

View File

@ -73,7 +73,7 @@ class TagService:
target must be bound to all requested tags.
"""
# Check if tag_ids is not empty to avoid WHERE false condition
if not tag_ids or len(tag_ids) == 0:
if not tag_ids:
return []
# Deduplicate repeated query params so match_all counts each requested tag once.
requested_tag_ids = list(dict.fromkeys(tag_ids))
@ -88,7 +88,7 @@ class TagService:
return []
tag_ids = list(tags)
# Check if tag_ids is not empty to avoid WHERE false condition
if not tag_ids or len(tag_ids) == 0:
if not tag_ids:
return []
if match_all:
if len(tag_ids) != len(requested_tag_ids):