add: app data query cache option
This commit is contained in:
parent
fdbc08912d
commit
8116307ba0
11 changed files with 100 additions and 49 deletions
|
@ -27,7 +27,7 @@ tetratto-shared = { path = "../shared" }
|
|||
tetratto-core = { path = "../core" }
|
||||
tetratto-l10n = { path = "../l10n" }
|
||||
image = "0.25.6"
|
||||
reqwest = { version = "0.12.22", features = ["json", "stream"] }
|
||||
reqwest = { version = "0.12.23", features = ["json", "stream"] }
|
||||
regex = "1.11.1"
|
||||
serde_json = "1.0.142"
|
||||
mime_guess = "2.0.5"
|
||||
|
@ -42,7 +42,7 @@ async-stripe = { version = "0.41.0", features = [
|
|||
"runtime-tokio-hyper",
|
||||
"connect",
|
||||
] }
|
||||
emojis = "0.7.1"
|
||||
emojis = "0.7.2"
|
||||
webp = "0.3.0"
|
||||
nanoneo = "0.2.0"
|
||||
cookie = "0.18.1"
|
||||
|
|
|
@ -65,7 +65,11 @@
|
|||
(option
|
||||
("value" "Tier3")
|
||||
("selected" "{% if app.storage_capacity == 'Tier3' -%}true{% else %}false{%- endif %}")
|
||||
(text "Tier 3 (100 MB)")))))
|
||||
(text "Tier 3 (100 MB)"))
|
||||
(option
|
||||
("value" "Unlimited")
|
||||
("selected" "{% if app.storage_capacity == 'Unlimited' -%}true{% else %}false{%- endif %}")
|
||||
(text "Unlimited")))))
|
||||
(text "{%- endif %}")
|
||||
(div
|
||||
("class" "card_nest")
|
||||
|
|
|
@ -4,10 +4,14 @@ use crate::{
|
|||
State,
|
||||
};
|
||||
use axum::{extract::Path, http::HeaderMap, response::IntoResponse, Extension, Json};
|
||||
use tetratto_core::model::{
|
||||
apps::{AppData, AppDataQuery, AppDataQueryResult},
|
||||
ApiReturn, Error,
|
||||
use tetratto_core::{
|
||||
cache::Cache,
|
||||
model::{
|
||||
apps::{AppData, AppDataQuery, AppDataQueryResult},
|
||||
ApiReturn, Error,
|
||||
},
|
||||
};
|
||||
use tetratto_shared::hash::hash;
|
||||
|
||||
pub async fn get_app_request(
|
||||
headers: HeaderMap,
|
||||
|
@ -37,6 +41,24 @@ pub async fn query_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
let query_hash = hash(serde_json::to_string(&req.query).unwrap());
|
||||
let redis_query_key = format!("atto.app.{}:{query_hash}", app.id);
|
||||
|
||||
if req.cache {
|
||||
if let Some(x) = data.0.1.get(redis_query_key.clone()).await {
|
||||
match serde_json::from_str::<AppDataQueryResult>(&x) {
|
||||
Ok(x) => {
|
||||
return Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Success".to_string(),
|
||||
payload: Some(x),
|
||||
});
|
||||
}
|
||||
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match data
|
||||
.query_app_data(AppDataQuery {
|
||||
app: app.id,
|
||||
|
@ -45,11 +67,26 @@ pub async fn query_request(
|
|||
})
|
||||
.await
|
||||
{
|
||||
Ok(x) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Success".to_string(),
|
||||
payload: Some(x),
|
||||
}),
|
||||
Ok(x) => {
|
||||
// store
|
||||
if req.cache {
|
||||
if !data
|
||||
.0
|
||||
.1
|
||||
.set(redis_query_key, serde_json::to_string(&x).unwrap())
|
||||
.await
|
||||
{
|
||||
return Json(Error::Unknown.into());
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Success".to_string(),
|
||||
payload: Some(x),
|
||||
})
|
||||
}
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1276,6 +1276,7 @@ pub struct InsertAppData {
|
|||
pub struct QueryAppData {
|
||||
pub query: AppDataSelectQuery,
|
||||
pub mode: AppDataSelectMode,
|
||||
pub cache: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue