fix: get cache correctly from redis
Some checks failed
ci/woodpecker/push/build-and-publish Pipeline failed
ci/woodpecker/push/publish-docs Pipeline failed

This commit is contained in:
Radical 2025-07-20 20:25:15 +02:00
parent eb7e5503de
commit 8a58774359
4 changed files with 14 additions and 7 deletions

View file

@ -35,8 +35,9 @@ pub async fn get(
if let Ok(cache_hit) = app_state
.get_cache_key(format!("{guild_uuid}_channels"))
.await
&& let Ok(channels) = serde_json::from_str::<Vec<Channel>>(&cache_hit)
{
return Ok((StatusCode::OK, Json(cache_hit)).into_response());
return Ok((StatusCode::OK, Json(channels)).into_response());
}
let channels = Channel::fetch_all(&app_state.pool, guild_uuid).await?;

View file

@ -35,8 +35,10 @@ pub async fn get(
Member::check_membership(&mut conn, uuid, guild_uuid).await?;
if let Ok(cache_hit) = app_state.get_cache_key(format!("{guild_uuid}_roles")).await {
return Ok((StatusCode::OK, Json(cache_hit)).into_response());
if let Ok(cache_hit) = app_state.get_cache_key(format!("{guild_uuid}_roles")).await
&& let Ok(roles) = serde_json::from_str::<Vec<Role>>(&cache_hit)
{
return Ok((StatusCode::OK, Json(roles)).into_response());
}
let roles = Role::fetch_all(&mut conn, guild_uuid).await?;

View file

@ -27,8 +27,10 @@ pub async fn get(
Member::check_membership(&mut conn, uuid, guild_uuid).await?;
if let Ok(cache_hit) = app_state.get_cache_key(format!("{role_uuid}")).await {
return Ok((StatusCode::OK, Json(cache_hit)).into_response());
if let Ok(cache_hit) = app_state.get_cache_key(format!("{role_uuid}")).await
&& let Ok(role) = serde_json::from_str::<Role>(&cache_hit)
{
return Ok((StatusCode::OK, Json(role)).into_response());
}
let role = Role::fetch_one(&mut conn, role_uuid).await?;