瀏覽代碼

Update StatusHashtagService, fix count bug

Daniel Supernault 5 年之前
父節點
當前提交
fe736f2b44
共有 1 個文件被更改,包括 5 次插入5 次删除
  1. 5 5
      app/Services/StatusHashtagService.php

+ 5 - 5
app/Services/StatusHashtagService.php

@@ -56,11 +56,11 @@ class StatusHashtagService {
 
 	public static function count($id)
 	{
-		$count = Redis::zcount(self::CACHE_KEY . $id, '-inf', '+inf');
-		if(empty($count)) {
-			$count = StatusHashtag::whereHashtagId($id)->count();
-		}
-		return $count;
+		$key = 'pf:services:status-hashtag:count:' . $id;
+		$ttl = now()->addHours(6);
+		return Cache::remember($key, $ttl, function() use($id) {
+			return StatusHashtag::whereHashtagId($id)->count();
+		});
 	}
 
 	public static function getStatus($statusId, $hashtagId)