File tree Expand file tree Collapse file tree 2 files changed +11
-7
lines changed
Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change 88from app .core .manager import core_manager
99from app .db import GetDB
1010from app .db .crud .host import get_host_by_id , get_hosts , upsert_inbounds
11- from app .db .models import ProxyHost , ProxyHostSecurity
12- from app .models .host import MuxSettings , TransportSettings , BaseHost
11+ from app .db .models import ProxyHostSecurity
12+ from app .models .host import BaseHost
1313
1414
1515def _prepare_host_data (host : BaseHost ) -> dict :
@@ -36,6 +36,7 @@ def _prepare_host_data(host: BaseHost) -> dict:
3636 else {},
3737 "status" : host .status ,
3838 "ech_config_list" : host .ech_config_list ,
39+ "priority" : host .priority ,
3940 }
4041
4142
@@ -108,7 +109,9 @@ async def get_host(self, id: int) -> dict | None:
108109 @cached ()
109110 async def get_hosts (self ) -> dict [int , dict ]:
110111 async with self ._lock :
111- return deepcopy (self ._hosts )
112+ # Return hosts sorted by priority
113+ sorted_hosts = dict (sorted (self ._hosts .items (), key = lambda x : x [1 ]["priority" ]))
114+ return deepcopy (sorted_hosts )
112115
113116
114117host_manager : HostManager = HostManager ()
Original file line number Diff line number Diff line change @@ -123,20 +123,21 @@ async def get_hosts(
123123 db : AsyncSession ,
124124 offset : Optional [int ] = 0 ,
125125 limit : Optional [int ] = 0 ,
126- sort : ProxyHostSortingOptions = " priority" ,
126+ sort : ProxyHostSortingOptions = ProxyHostSortingOptions . priority ,
127127) -> list [ProxyHost ]:
128128 """
129- Retrieves hosts.
129+ Retrieves hosts sorted by priority (ascending) by default .
130130
131131 Args:
132132 db (AsyncSession): Database session.
133133 offset (Optional[int]): Number of records to skip.
134134 limit (Optional[int]): Number of records to retrieve.
135+ sort (ProxyHostSortingOptions): Sorting option. Defaults to priority ascending.
135136
136137 Returns:
137- List[ProxyHost]: List of hosts for the inbound .
138+ List[ProxyHost]: List of hosts sorted by the specified option .
138139 """
139- stmt = select (ProxyHost ).order_by (sort )
140+ stmt = select (ProxyHost ).order_by (sort . value )
140141
141142 if offset :
142143 stmt = stmt .offset (offset )
You can’t perform that action at this time.
0 commit comments