diff --git a/src/backend/backend.py b/src/backend/backend.py index 594d18b8..959efa47 100644 --- a/src/backend/backend.py +++ b/src/backend/backend.py @@ -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() diff --git a/src/gui/Pages/AddAccount/ServerBrowser.qml b/src/gui/Pages/AddAccount/ServerBrowser.qml index 7f7097c4..7d6cbd09 100644 --- a/src/gui/Pages/AddAccount/ServerBrowser.qml +++ b/src/gui/Pages/AddAccount/ServerBrowser.qml @@ -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 } }