-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ApproveContent then refresh user table DiscussionCount and CommentCount #16
ApproveContent then refresh user table DiscussionCount and CommentCount #16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thank you!
Would it make sense to move The discussion count shouldn't change unless we're also approving the discussion. This probably doesn't have a big impact but would save a database query where possible. |
Agreed. |
@clarkwinkelmann Do you mean the |
Sorry I didn't reply to this right away. Yes now that I re-read my suggestion it requires a bit more code. Essentially this: if ($post->number == 1) {
$discussion->is_approved = true;
}
$discussion->save();
$user->refreshDiscussionCount();
$user->refreshCommentCount();
$user->save(); could be replaced with if ($post->number == 1) {
$discussion->is_approved = true;
}
$discussion->save();
if ($post->number == 1) {
$user->refreshDiscussionCount();
}
$user->refreshCommentCount();
$user->save(); or if ($post->number == 1) {
$discussion->is_approved = true;
$discussion->afterSave(function () use ($user) {
$user->refreshDiscussionCount();
});
}
$discussion->save();
$user->refreshCommentCount();
$user->save(); To save a database request. Not sure if it's worth the optimization though. |
I like the second one |
@imzhi would you be interested in updating this PR as discussed above? |
1cac468
to
66f42d3
Compare
@askvortsov1 A new commit was finished based on the discussion. |
After approve the operation, update the
discussion_count
andcomment_count
fields of theusers
table