From 9937bc0dc7ed107aad1fcfd5b92ab56c8f961a6f Mon Sep 17 00:00:00 2001 From: hole-thu Date: Thu, 2 Jun 2022 23:52:16 +0800 Subject: [PATCH] fix bugs --- src/api/attention.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/api/attention.rs b/src/api/attention.rs index 37e2cea..a86c7dc 100644 --- a/src/api/attention.rs +++ b/src/api/attention.rs @@ -35,17 +35,22 @@ pub async fn attention_post( if att.has(ai.pid).await? != switch_to { if switch_to { att.add(ai.pid).await?; - delta = (p.n_attentions < 3 * p.n_comments) as i32; + delta = 1; } else { att.remove(ai.pid).await?; delta = -1; } + let hot_delta = if p.n_attentions <= 3 * p.n_comments { + delta * 2 + } else { + 0 + }; update!( p, posts, &db, { n_attentions, add delta }, - { hot_score, add delta * 2 } + { hot_score, add hot_delta } ); if switch_to && user.is_admin { update!(p, posts, &db, { is_reported, to false });