Преглед изворни кода

Update Profile, fix follower counter bug

Daniel Supernault пре 4 година
родитељ
комит
d06bec9cd9
1 измењених фајлова са 8 додато и 12 уклоњено
  1. 8 12
      app/Profile.php

+ 8 - 12
app/Profile.php

@@ -65,13 +65,11 @@ class Profile extends Model
     public function followingCount($short = false)
     public function followingCount($short = false)
     {
     {
         $count = Cache::remember('profile:following_count:'.$this->id, now()->addMonths(1), function() {
         $count = Cache::remember('profile:following_count:'.$this->id, now()->addMonths(1), function() {
-            $count = $this->following_count;
-            if($count) {
-                return $count;
-            }
             $count = $this->following()->count();
             $count = $this->following()->count();
-            $this->following_count = $count;
-            $this->save();
+            if($this->following_count != $count) {
+                $this->following_count = $count;
+                $this->save();
+            }
             return $count;
             return $count;
         });
         });
 
 
@@ -81,13 +79,11 @@ class Profile extends Model
     public function followerCount($short = false)
     public function followerCount($short = false)
     {
     {
         $count = Cache::remember('profile:follower_count:'.$this->id, now()->addMonths(1), function() {
         $count = Cache::remember('profile:follower_count:'.$this->id, now()->addMonths(1), function() {
-            $count = $this->followers_count;
-            if($count) {
-                return $count;
-            }
             $count = $this->followers()->count();
             $count = $this->followers()->count();
-            $this->followers_count = $count;
-            $this->save();
+            if($this->followers_count != $count) {
+                $this->followers_count = $count;
+                $this->save();
+            }
             return $count;
             return $count;
         });
         });
         return $short ? PrettyNumber::convert($count) : $count;
         return $short ? PrettyNumber::convert($count) : $count;