瀏覽代碼

Update HashtagService, improve count perf

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

+ 3 - 2
app/Services/HashtagService.php

@@ -29,8 +29,9 @@ class HashtagService
 
     public static function count($id)
     {
-        return Cache::remember('services:hashtag:public-count:by_id:' . $id, 86400, function() use($id) {
-            return StatusHashtag::whereHashtagId($id)->whereStatusVisibility('public')->count();
+        return Cache::remember('services:hashtag:public-count:by_id:' . $id, 3600, function() use($id) {
+            $tag = Hashtag::find($id);
+            return $tag ? $tag->cached_count ?? 0 : 0;
         });
     }