From 5ac9d0e8f2f14f11ee4c502f66c2cf518271aad9 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 9 Feb 2021 00:42:12 -0700 Subject: [PATCH] Update Embeds. Fix Profile + Status embeds, remove following count and improve cache invalidation and hidden follower counts --- app/Http/Controllers/ComposeController.php | 1 + app/Http/Controllers/Settings/PrivacySettings.php | 3 +++ app/Profile.php | 6 ++++++ resources/views/profile/embed-removed.blade.php | 12 +++++++++--- resources/views/profile/embed.blade.php | 6 +----- resources/views/status/embed-removed.blade.php | 12 +++++++++--- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/ComposeController.php b/app/Http/Controllers/ComposeController.php index d2003dddc..6e8d28358 100644 --- a/app/Http/Controllers/ComposeController.php +++ b/app/Http/Controllers/ComposeController.php @@ -427,6 +427,7 @@ class ComposeController extends Controller Cache::forget('profile:status_count:'.$profile->id); Cache::forget('status:transformer:media:attachments:'.$status->id); Cache::forget($user->storageUsedKey()); + Cache::forget('profile:embed:' . $status->profile_id); return $status->url(); } diff --git a/app/Http/Controllers/Settings/PrivacySettings.php b/app/Http/Controllers/Settings/PrivacySettings.php index 91f1ac43c..30bc40909 100644 --- a/app/Http/Controllers/Settings/PrivacySettings.php +++ b/app/Http/Controllers/Settings/PrivacySettings.php @@ -74,6 +74,9 @@ trait PrivacySettings } Cache::forget('profile:settings:' . $profile->id); Cache::forget('user:account:id:' . $profile->user_id); + Cache::forget('profile:follower_count:' . $profile->id); + Cache::forget('profile:following_count:' . $profile->id); + Cache::forget('profile:embed:' . $profile->id); return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!'); } diff --git a/app/Profile.php b/app/Profile.php index c527cccd5..d4532fcb1 100644 --- a/app/Profile.php +++ b/app/Profile.php @@ -65,6 +65,9 @@ class Profile extends Model public function followingCount($short = false) { $count = Cache::remember('profile:following_count:'.$this->id, now()->addMonths(1), function() { + if($this->domain == null && $this->user->settings->show_profile_following_count == false) { + return 0; + } $count = $this->following()->count(); if($this->following_count != $count) { $this->following_count = $count; @@ -79,6 +82,9 @@ class Profile extends Model public function followerCount($short = false) { $count = Cache::remember('profile:follower_count:'.$this->id, now()->addMonths(1), function() { + if($this->domain == null && $this->user->settings->show_profile_follower_count == false) { + return 0; + } $count = $this->followers()->count(); if($this->followers_count != $count) { $this->followers_count = $count; diff --git a/resources/views/profile/embed-removed.blade.php b/resources/views/profile/embed-removed.blade.php index 5cb28218b..7a49d2e79 100644 --- a/resources/views/profile/embed-removed.blade.php +++ b/resources/views/profile/embed-removed.blade.php @@ -18,7 +18,13 @@ -
-
+
+

Pixelfed

diff --git a/resources/views/profile/embed.blade.php b/resources/views/profile/embed.blade.php index 3d5e3de11..caf3fd3df 100644 --- a/resources/views/profile/embed.blade.php +++ b/resources/views/profile/embed.blade.php @@ -54,13 +54,9 @@

Posts

-

{{$profile->followers()->count()}}

+

{{$profile->followerCount(true)}}

Followers

-
-

{{$profile->following()->count()}}

-

Following

-
diff --git a/resources/views/status/embed-removed.blade.php b/resources/views/status/embed-removed.blade.php index 3e147ec89..e5f94525b 100644 --- a/resources/views/status/embed-removed.blade.php +++ b/resources/views/status/embed-removed.blade.php @@ -18,7 +18,13 @@ -
-
+
+

Pixelfed