Simplify pinging & properly close aiohttp session
This commit is contained in:
parent
f327c99a99
commit
9cc9229fdb
|
@ -114,8 +114,6 @@ class Backend:
|
|||
self._sso_server: Optional[SSOServer] = None
|
||||
self._sso_server_task: Optional[asyncio.Future] = None
|
||||
|
||||
self._ping_tasks: Dict[str, asyncio.Future] = {}
|
||||
|
||||
self.profile_cache: Dict[str, nio.ProfileGetResponse] = {}
|
||||
self.get_profile_locks: DefaultDict[str, asyncio.Lock] = \
|
||||
DefaultDict(asyncio.Lock) # {user_id: lock}
|
||||
|
@ -565,6 +563,7 @@ class Backend:
|
|||
tmout = aiohttp.ClientTimeout(total=20)
|
||||
session = aiohttp.ClientSession(raise_for_status=True, timeout=tmout)
|
||||
response = await session.get(api_list)
|
||||
coros = []
|
||||
|
||||
for server in (await response.json()):
|
||||
homeserver_url = server["homeserver"]
|
||||
|
@ -578,9 +577,6 @@ class Backend:
|
|||
if server["country"] == "USA":
|
||||
server["country"] = "United States"
|
||||
|
||||
if homeserver_url in self._ping_tasks:
|
||||
self._ping_tasks[homeserver_url].cancel()
|
||||
|
||||
self.models["homeservers"][homeserver_url] = Homeserver(
|
||||
id = homeserver_url,
|
||||
name = server["name"],
|
||||
|
@ -590,6 +586,7 @@ class Backend:
|
|||
self._get_homeserver_stability(server["monitor"]["logs"]),
|
||||
)
|
||||
|
||||
self._ping_tasks[homeserver_url] = asyncio.ensure_future(
|
||||
self._ping_homeserver(session, homeserver_url),
|
||||
)
|
||||
coros.append(self._ping_homeserver(session, homeserver_url))
|
||||
|
||||
await asyncio.gather(*coros)
|
||||
await session.close()
|
||||
|
|
|
@ -27,12 +27,13 @@ HBox {
|
|||
function takeFocus() { serverField.item.field.forceActiveFocus() }
|
||||
|
||||
function fetchServers() {
|
||||
if (fetchServersFuture) fetchServersFuture.cancel()
|
||||
|
||||
fetchServersFuture = py.callCoro("fetch_homeservers", [], () => {
|
||||
fetchServersFuture = null
|
||||
}, (type, args, error, traceback) => {
|
||||
fetchServersFuture = null
|
||||
// TODO
|
||||
print( traceback)
|
||||
print( traceback) // TODO: display error graphically
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -283,7 +284,7 @@ HBox {
|
|||
height: width
|
||||
|
||||
source: "../../Base/HBusyIndicator.qml"
|
||||
active: box.fetchServersFuture
|
||||
active: box.fetchServersFuture && ! serverList.count
|
||||
opacity: active ? 1 : 0
|
||||
|
||||
Behavior on opacity { HNumberAnimation { factor: 2 } }
|
||||
|
|
Loading…
Reference in New Issue
Block a user