1
0
mirror of https://github.com/flarum/core.git synced 2025-07-20 08:11:27 +02:00

Don't save in the model

This commit is contained in:
Toby Zerner
2018-07-21 21:28:44 +09:30
parent d9cfc0e1b2
commit 73da82ebc0
2 changed files with 10 additions and 4 deletions

View File

@@ -766,7 +766,6 @@ class User extends AbstractModel
public function refreshCommentsCount() public function refreshCommentsCount()
{ {
$this->comments_count = $this->posts()->count(); $this->comments_count = $this->posts()->count();
$this->save();
return $this; return $this;
} }
@@ -779,7 +778,6 @@ class User extends AbstractModel
public function refreshDiscussionsCount() public function refreshDiscussionsCount()
{ {
$this->discussions_count = $this->discussions()->count(); $this->discussions_count = $this->discussions()->count();
$this->save();
return $this; return $this;
} }

View File

@@ -66,11 +66,19 @@ class UserMetadataUpdater
private function updateCommentsCount(Post $post) private function updateCommentsCount(Post $post)
{ {
optional($post->user)->refreshCommentsCount(); $user = $post->user;
if ($user && $user->exists) {
$user->refreshCommentsCount()->save();
}
} }
private function updateDiscussionsCount(Discussion $discussion) private function updateDiscussionsCount(Discussion $discussion)
{ {
optional($discussion->startUser)->refreshDiscussionsCount(); $user = $discussion->startUser;
if ($user && $user->exists) {
$user->refreshDiscussionsCount()->save();
}
} }
} }