diff --git a/app/Http/Controllers/InternalApiController.php b/app/Http/Controllers/InternalApiController.php index acabcb0a7..d031adef4 100644 --- a/app/Http/Controllers/InternalApiController.php +++ b/app/Http/Controllers/InternalApiController.php @@ -347,6 +347,7 @@ class InternalApiController extends Controller NewStatusPipeline::dispatch($status); Cache::forget('user:account:id:'.$profile->user_id); + Cache::forget('profile:status_count:'.$profile->id); return $status->url(); } } diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index b22464404..fbf3acc28 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -196,7 +196,8 @@ class StatusController extends Controller } $status->type = (new self)::mimeTypeCheck($mimes); $status->save(); - + + Cache::forget('profile:status_count:'.$profile->id); NewStatusPipeline::dispatch($status); // TODO: Send to subscribers @@ -215,6 +216,7 @@ class StatusController extends Controller $status = Status::findOrFail($request->input('item')); if ($status->profile_id === Auth::user()->profile->id || Auth::user()->is_admin == true) { + Cache::forget('profile:status_count:'.$status->profile_id); StatusDelete::dispatch($status); } if($request->wantsJson()) { diff --git a/app/Profile.php b/app/Profile.php index 7fba6bc9a..57aadb4c6 100644 --- a/app/Profile.php +++ b/app/Profile.php @@ -125,7 +125,7 @@ class Profile extends Model public function avatarUrl() { - $url = Cache::remember("avatar:{$this->id}", now()->addYears(1), function () { + $url = Cache::remember('avatar:'.$this->id, now()->addYears(1), function () { $avatar = $this->avatar; $path = $avatar->media_path; $version = hash('sha256', $avatar->change_count); @@ -139,36 +139,20 @@ class Profile extends Model public function statusCount() { - return $this->statuses() - ->getQuery() - ->whereHas('media') - ->whereNull('in_reply_to_id') - ->whereNull('reblog_of_id') - ->count(); + 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 public function recommendFollowers() { - $follows = $this->following()->pluck('followers.id'); - $following = $this->following() - ->orderByRaw('rand()') - ->take(3) - ->pluck('following_id'); - $following->push(Auth::id()); - $following = Follower::whereNotIn('profile_id', $follows) - ->whereNotIn('following_id', $following) - ->whereNotIn('following_id', $follows) - ->whereIn('profile_id', $following) - ->orderByRaw('rand()') - ->distinct('id') - ->limit(3) - ->pluck('following_id'); - $recommended = []; - foreach ($following as $follow) { - $recommended[] = self::findOrFail($follow); - } - - return $recommended; + return collect([]); } public function keyId() diff --git a/app/Transformer/Api/AccountTransformer.php b/app/Transformer/Api/AccountTransformer.php index 2c6cbcd50..0fd3ef21a 100644 --- a/app/Transformer/Api/AccountTransformer.php +++ b/app/Transformer/Api/AccountTransformer.php @@ -19,7 +19,7 @@ class AccountTransformer extends Fractal\TransformerAbstract 'created_at' => null, 'followers_count' => $profile->followerCount(), 'following_count' => $profile->followingCount(), - 'statuses_count' => $profile->statusCount(), + 'statuses_count' => (int) $profile->statusCount(), 'note' => $profile->bio, 'url' => $profile->url(), 'avatar' => $profile->avatarUrl(), @@ -30,7 +30,7 @@ class AccountTransformer extends Fractal\TransformerAbstract 'moved' => null, 'fields' => null, 'bot' => null, - 'website' => $profile->website, + 'website' => null, 'software' => 'pixelfed', 'is_admin' => (bool) $is_admin ];