MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / _ensure_single_default_proxy

Function _ensure_single_default_proxy

src/database/crud.py:502–530  ·  view source on GitHub ↗

保证代理表中“有且仅有一个默认代理”: - 没有默认时,自动使用最早创建(ID 最小)的代理作为默认 - 有多个默认时,仅保留最早的一个

(db: Session)

Source from the content-addressed store, hash-verified

500# ============================================================================
501
502def _ensure_single_default_proxy(db: Session) -> Optional[Proxy]:
503 """
504 保证代理表中“有且仅有一个默认代理”:
505 - 没有默认时,自动使用最早创建(ID 最小)的代理作为默认
506 - 有多个默认时,仅保留最早的一个
507 """
508 proxies = db.query(Proxy).order_by(asc(Proxy.id)).all()
509 if not proxies:
510 return None
511
512 default_proxies = [proxy for proxy in proxies if bool(proxy.is_default)]
513 keeper = default_proxies[0] if default_proxies else proxies[0]
514 changed = False
515
516 if not keeper.is_default:
517 keeper.is_default = True
518 changed = True
519
520 for proxy in proxies:
521 should_default = proxy.id == keeper.id
522 if bool(proxy.is_default) != should_default:
523 proxy.is_default = should_default
524 changed = True
525
526 if changed:
527 db.commit()
528 db.refresh(keeper)
529
530 return keeper
531
532
533def create_proxy(

Callers 4

create_proxyFunction · 0.85
get_proxiesFunction · 0.85
delete_proxyFunction · 0.85
get_random_proxyFunction · 0.85

Calls 2

allMethod · 0.80
queryMethod · 0.45

Tested by

no test coverage detected