mirror of
https://github.com/flarum/framework.git
synced 2024-12-03 07:33:36 +08:00
Don't save in the model
This commit is contained in:
parent
d9cfc0e1b2
commit
73da82ebc0
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user