完成评论统计

This commit is contained in:
augushong
2021-01-03 22:02:34 +08:00
parent 3b5a56aef5
commit cc83df7fb9
5 changed files with 43 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace app\model;
use app\index\controller\Common;
use think\facade\Cache;
use think\Model;
/**
@@ -32,4 +33,23 @@ class PostComment extends Model
return $read_url;
}
public static function getPostCommentsCount($post_id)
{
$cache_key = 'post_comment_count_' . $post_id;
$count = Cache::get($cache_key);
if (is_null($count)) {
$count = PostComment::where('post_id', $post_id)->count();
Cache::tag('comment')->set($cache_key, $count);
}
return $count;
}
public static function clearCountCache()
{
Cache::tag('comment')->clear();
}
}