api: implement caching for lock discovery

This commit is contained in:
lilly 2026-05-09 21:30:53 +02:00
commit 5658228ce2
Signed by: lilly
SSH key fingerprint: SHA256:y9T5GFw2A20WVklhetIxG1+kcg/Ce0shnQmbu1LQ37g

View file

@ -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}}) @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]:
locks = await ccujack.find_locks() # discover locks from ccujack
CACHE_KEY = "ccu-find-locks"
# TODO: Properly associate parameters with their values if CACHE_KEY in cache:
# values = await asyncio.gather(*[ locks = cache[CACHE_KEY]
# ccujack.query_param_value(f"{i_lock.address}/{i_channel.index}/{i_param.id}/~pv") else:
# for i_lock, lock_channels in locks locks = await ccujack.find_locks()
# for i_channel, channel_params in lock_channels cache[CACHE_KEY] = locks
# for i_param in channel_params
# ])
# assemble result objects # assemble result objects
result = [] result = []