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

Function get_random_proxy

src/database/crud.py:634–654  ·  view source on GitHub ↗

获取一个启用代理:优先默认代理,否则使用最早启用的代理。

(db: Session)

Source from the content-addressed store, hash-verified

632
633
634def get_random_proxy(db: Session) -> Optional[Proxy]:
635 """获取一个启用代理:优先默认代理,否则使用最早启用的代理。"""
636 _ensure_single_default_proxy(db)
637
638 # 优先返回启用状态下的默认代理
639 default_proxy = (
640 db.query(Proxy)
641 .filter(Proxy.enabled == True, Proxy.is_default == True)
642 .order_by(asc(Proxy.id))
643 .first()
644 )
645 if default_proxy:
646 return default_proxy
647
648 # 默认代理不可用时,回退到最早启用的代理(稳定而可预期)
649 return (
650 db.query(Proxy)
651 .filter(Proxy.enabled == True)
652 .order_by(asc(Proxy.id))
653 .first()
654 )
655
656
657def set_proxy_default(db: Session, proxy_id: int) -> Optional[Proxy]:

Callers

nothing calls this directly

Calls 4

firstMethod · 0.80
filterMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected