|
@@ -64,22 +64,52 @@ class Profile extends Model
|
|
|
|
|
|
public function followingCount($short = false)
|
|
public function followingCount($short = false)
|
|
{
|
|
{
|
|
- $count = $this->following()->count();
|
|
|
|
- if ($short) {
|
|
|
|
- return PrettyNumber::convert($count);
|
|
|
|
- } else {
|
|
|
|
|
|
+ $count = Cache::remember('profile:following_count:'.$this->id, now()->addMonths(1), function() {
|
|
|
|
+ $count = $this->following_count;
|
|
|
|
+ if($count) {
|
|
|
|
+ return $count;
|
|
|
|
+ }
|
|
|
|
+ $count = $this->following()->count();
|
|
|
|
+ $this->following_count = $count;
|
|
|
|
+ $this->save();
|
|
return $count;
|
|
return $count;
|
|
- }
|
|
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return $short ? PrettyNumber::convert($count) : $count;
|
|
}
|
|
}
|
|
|
|
|
|
public function followerCount($short = false)
|
|
public function followerCount($short = false)
|
|
{
|
|
{
|
|
- $count = $this->followers()->count();
|
|
|
|
- if ($short) {
|
|
|
|
- return PrettyNumber::convert($count);
|
|
|
|
- } else {
|
|
|
|
|
|
+ $count = Cache::remember('profile:follower_count:'.$this->id, now()->addMonths(1), function() {
|
|
|
|
+ $count = $this->followers_count;
|
|
|
|
+ if($count) {
|
|
|
|
+ return $count;
|
|
|
|
+ }
|
|
|
|
+ $count = $this->followers()->count();
|
|
|
|
+ $this->followers_count = $count;
|
|
|
|
+ $this->save();
|
|
return $count;
|
|
return $count;
|
|
- }
|
|
|
|
|
|
+ });
|
|
|
|
+ return $short ? PrettyNumber::convert($count) : $count;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function statusCount()
|
|
|
|
+ {
|
|
|
|
+ return Cache::remember('profile:status_count:'.$this->id, now()->addMonths(1), function() {
|
|
|
|
+ $count = $this->status_count;
|
|
|
|
+ if($count) {
|
|
|
|
+ return $count;
|
|
|
|
+ }
|
|
|
|
+ $count = $this->statuses()
|
|
|
|
+ ->getQuery()
|
|
|
|
+ ->whereHas('media')
|
|
|
|
+ ->whereNull('in_reply_to_id')
|
|
|
|
+ ->whereNull('reblog_of_id')
|
|
|
|
+ ->count();
|
|
|
|
+ $this->status_count = $count;
|
|
|
|
+ $this->save();
|
|
|
|
+ return $count;
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
public function following()
|
|
public function following()
|
|
@@ -148,18 +178,6 @@ class Profile extends Model
|
|
return $url;
|
|
return $url;
|
|
}
|
|
}
|
|
|
|
|
|
- public function statusCount()
|
|
|
|
- {
|
|
|
|
- return Cache::remember('profile:status_count:'.$this->id, now()->addMonths(1), function() {
|
|
|
|
- return $this->statuses()
|
|
|
|
- ->getQuery()
|
|
|
|
- ->whereHas('media')
|
|
|
|
- ->whereNull('in_reply_to_id')
|
|
|
|
- ->whereNull('reblog_of_id')
|
|
|
|
- ->count();
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// deprecated
|
|
// deprecated
|
|
public function recommendFollowers()
|
|
public function recommendFollowers()
|
|
{
|
|
{
|