feat: cache for posts list
This commit is contained in:
@@ -92,7 +92,7 @@ pub async fn add_comment(
|
||||
rconn: RdsConn,
|
||||
) -> API<Value> {
|
||||
let mut p = Post::get(&db, &rconn, ci.pid).await?;
|
||||
Comment::create(
|
||||
let c = Comment::create(
|
||||
&db,
|
||||
NewComment {
|
||||
content: ci.text.to_string(),
|
||||
@@ -104,6 +104,7 @@ pub async fn add_comment(
|
||||
)
|
||||
.await?;
|
||||
p.change_n_comments(&db, 1).await?;
|
||||
p.update_comment_time(&db, c.create_time).await?;
|
||||
// auto attention after comment
|
||||
let mut att = Attention::init(&user.namehash, &rconn);
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ pub async fn delete(
|
||||
_ => return Err(APIError::PcError(NotAllowed)),
|
||||
}
|
||||
|
||||
p.refresh_cache(&rconn, false).await;
|
||||
// 如果是删除,需要也从0号缓存队列中去掉
|
||||
p.refresh_cache(&rconn, true).await;
|
||||
|
||||
Ok(json!({
|
||||
"code": 0
|
||||
|
||||
@@ -67,7 +67,10 @@ async fn p2output(p: &Post, user: &CurrentUser, db: &Db, rconn: &RdsConn) -> Pos
|
||||
None
|
||||
} else {
|
||||
// 单个洞还有查询评论的接口,这里挂了不用报错
|
||||
p.get_comments(db, rconn).await.ok().map(|cs| c2output(p, &cs, user))
|
||||
p.get_comments(db, rconn)
|
||||
.await
|
||||
.ok()
|
||||
.map(|cs| c2output(p, &cs, user))
|
||||
},
|
||||
can_del: p.check_permission(user, "wd").is_ok(),
|
||||
attention: Attention::init(&user.namehash, &rconn)
|
||||
@@ -117,7 +120,7 @@ pub async fn get_list(
|
||||
let page = p.unwrap_or(1);
|
||||
let page_size = 25;
|
||||
let start = (page - 1) * page_size;
|
||||
let ps = Post::gets_by_page(&db, order_mode, start.into(), page_size.into()).await?;
|
||||
let ps = Post::gets_by_page(&db, &rconn, order_mode, start.into(), page_size.into()).await?;
|
||||
let ps_data = ps2outputs(&ps, &user, &db, &rconn).await;
|
||||
Ok(json!({
|
||||
"data": ps_data,
|
||||
@@ -147,6 +150,7 @@ pub async fn publish_post(
|
||||
)
|
||||
.await?;
|
||||
Attention::init(&user.namehash, &rconn).add(p.id).await?;
|
||||
p.refresh_cache(&rconn, true).await;
|
||||
Ok(json!({
|
||||
"code": 0
|
||||
}))
|
||||
|
||||
@@ -26,6 +26,7 @@ pub async fn search(
|
||||
} else {
|
||||
Post::search(
|
||||
&db,
|
||||
&rconn,
|
||||
search_mode,
|
||||
keywords.to_string(),
|
||||
start.into(),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::api::{CurrentUser, API};
|
||||
use crate::db_conn::Db;
|
||||
use crate::random_hasher::RandomHasher;
|
||||
use rocket::serde::json::{json, Value};
|
||||
use rocket::State;
|
||||
use crate::db_conn::Db;
|
||||
|
||||
#[get("/systemlog")]
|
||||
pub async fn get_systemlog(user: CurrentUser, rh: &State<RandomHasher>, db: Db) -> API<Value> {
|
||||
|
||||
Reference in New Issue
Block a user