Reduce Life360 update time by fetching Places & Members in parallel (#106277)

pull/106285/head
Phil Bruckner 2023-12-22 16:29:26 -06:00 committed by GitHub
parent a4357409c8
commit 963347b9c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import asyncio
from contextlib import suppress from contextlib import suppress
from dataclasses import dataclass, field from dataclasses import dataclass, field
from datetime import datetime from datetime import datetime
@ -130,8 +131,10 @@ class Life360DataUpdateCoordinator(DataUpdateCoordinator[Life360Data]):
for circle in await self._retrieve_data("get_circles"): for circle in await self._retrieve_data("get_circles"):
circle_id = circle["id"] circle_id = circle["id"]
circle_members = await self._retrieve_data("get_circle_members", circle_id) circle_members, circle_places = await asyncio.gather(
circle_places = await self._retrieve_data("get_circle_places", circle_id) self._retrieve_data("get_circle_members", circle_id),
self._retrieve_data("get_circle_places", circle_id),
)
data.circles[circle_id] = Life360Circle( data.circles[circle_id] = Life360Circle(
circle["name"], circle["name"],