diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 39158fe4c..a7567b35e 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -766,7 +766,6 @@ class User extends AbstractModel public function refreshCommentsCount() { $this->comments_count = $this->posts()->count(); - $this->save(); return $this; } @@ -779,7 +778,6 @@ class User extends AbstractModel public function refreshDiscussionsCount() { $this->discussions_count = $this->discussions()->count(); - $this->save(); return $this; } diff --git a/framework/core/src/User/UserMetadataUpdater.php b/framework/core/src/User/UserMetadataUpdater.php index 0814f4939..1297ea6bf 100644 --- a/framework/core/src/User/UserMetadataUpdater.php +++ b/framework/core/src/User/UserMetadataUpdater.php @@ -66,11 +66,19 @@ class UserMetadataUpdater private function updateCommentsCount(Post $post) { - optional($post->user)->refreshCommentsCount(); + $user = $post->user; + + if ($user && $user->exists) { + $user->refreshCommentsCount()->save(); + } } private function updateDiscussionsCount(Discussion $discussion) { - optional($discussion->startUser)->refreshDiscussionsCount(); + $user = $discussion->startUser; + + if ($user && $user->exists) { + $user->refreshDiscussionsCount()->save(); + } } }