fix: 修复候选调度中 priority 为 0 时被错误回退为默认值的问题

使用显式 is not None 判断替代 or 运算符,避免优先级为 0 时被当作 falsy 值处理
This commit is contained in:
fawney19
2026-02-09 12:58:27 +08:00
parent 8684548072
commit 34cdc26e6f

View File

@@ -1626,10 +1626,12 @@ class CacheAwareScheduler:
result.extend(sorted_group) result.extend(sorted_group)
else: else:
# 单个候选或没有 affinity_key按次要排序条件排序 # 单个候选或没有 affinity_key按次要排序条件排序
def secondary_sort(c: ProviderCandidate) -> Any: def secondary_sort(c: ProviderCandidate) -> tuple[int, int, str]:
pp = c.provider.provider_priority
ip = c.key.internal_priority if c.key else None
return ( return (
c.provider.provider_priority, pp if pp is not None else 999999,
c.key.internal_priority if c.key else 999999, ip if ip is not None else 999999,
c.key.id if c.key else "", c.key.id if c.key else "",
) )
@@ -1668,9 +1670,11 @@ class CacheAwareScheduler:
else: else:
# 提供商优先模式:按 (provider_priority, internal_priority) 分组 # 提供商优先模式:按 (provider_priority, internal_priority) 分组
for candidate in candidates: for candidate in candidates:
pp = candidate.provider.provider_priority
ip = candidate.key.internal_priority if candidate.key else None
key = ( key = (
candidate.provider.provider_priority or 999999, pp if pp is not None else 999999,
candidate.key.internal_priority if candidate.key else 999999, ip if ip is not None else 999999,
) )
priority_groups[key].append(candidate) priority_groups[key].append(candidate)