fix: get cache correctly from redis
This commit is contained in:
parent
eb7e5503de
commit
8a58774359
4 changed files with 14 additions and 7 deletions
|
@ -1,11 +1,13 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
middleware::from_fn_with_state, routing::{any, delete, get, patch}, Router
|
Router,
|
||||||
|
middleware::from_fn_with_state,
|
||||||
|
routing::{any, delete, get, patch},
|
||||||
};
|
};
|
||||||
//use socketioxide::SocketIo;
|
//use socketioxide::SocketIo;
|
||||||
|
|
||||||
use crate::{api::v1::auth::CurrentUser, AppState};
|
use crate::{AppState, api::v1::auth::CurrentUser};
|
||||||
|
|
||||||
mod uuid;
|
mod uuid;
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,9 @@ pub async fn get(
|
||||||
if let Ok(cache_hit) = app_state
|
if let Ok(cache_hit) = app_state
|
||||||
.get_cache_key(format!("{guild_uuid}_channels"))
|
.get_cache_key(format!("{guild_uuid}_channels"))
|
||||||
.await
|
.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?;
|
let channels = Channel::fetch_all(&app_state.pool, guild_uuid).await?;
|
||||||
|
|
|
@ -35,8 +35,10 @@ pub async fn get(
|
||||||
|
|
||||||
Member::check_membership(&mut conn, uuid, guild_uuid).await?;
|
Member::check_membership(&mut conn, uuid, guild_uuid).await?;
|
||||||
|
|
||||||
if let Ok(cache_hit) = app_state.get_cache_key(format!("{guild_uuid}_roles")).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());
|
&& 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?;
|
let roles = Role::fetch_all(&mut conn, guild_uuid).await?;
|
||||||
|
|
|
@ -27,8 +27,10 @@ pub async fn get(
|
||||||
|
|
||||||
Member::check_membership(&mut conn, uuid, guild_uuid).await?;
|
Member::check_membership(&mut conn, uuid, guild_uuid).await?;
|
||||||
|
|
||||||
if let Ok(cache_hit) = app_state.get_cache_key(format!("{role_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());
|
&& 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?;
|
let role = Role::fetch_one(&mut conn, role_uuid).await?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue