api: implement caching for lock discovery
This commit is contained in:
parent
c1a78e4dc9
commit
5658228ce2
1 changed files with 8 additions and 10 deletions
|
|
@ -117,16 +117,14 @@ async def login_callback(req: Request, resp: Response, oidc_client: deps.OpenidC
|
|||
|
||||
|
||||
@app.get("/api/locks/", tags=["locks"], responses={status.HTTP_401_UNAUTHORIZED: {"model": models.HttpProblemDetail}})
|
||||
async def list_locks(ccujack: deps.CCUJackClient) -> List[models.Lock]:
|
||||
async def list_locks(ccujack: deps.CCUJackClient, cache: deps.Cache) -> List[models.Lock]:
|
||||
# discover locks from ccujack
|
||||
CACHE_KEY = "ccu-find-locks"
|
||||
if CACHE_KEY in cache:
|
||||
locks = cache[CACHE_KEY]
|
||||
else:
|
||||
locks = await ccujack.find_locks()
|
||||
|
||||
# TODO: Properly associate parameters with their values
|
||||
# values = await asyncio.gather(*[
|
||||
# ccujack.query_param_value(f"{i_lock.address}/{i_channel.index}/{i_param.id}/~pv")
|
||||
# for i_lock, lock_channels in locks
|
||||
# for i_channel, channel_params in lock_channels
|
||||
# for i_param in channel_params
|
||||
# ])
|
||||
cache[CACHE_KEY] = locks
|
||||
|
||||
# assemble result objects
|
||||
result = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue