Skip to content
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

Merged

Conversation

imzhi
Copy link
Contributor

@imzhi imzhi commented Feb 28, 2020

After approve the operation, update the discussion_count and comment_count fields of the users table

Copy link
Member

@askvortsov1 askvortsov1 left a 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!

@clarkwinkelmann
Copy link
Member

Would it make sense to move $user->refreshDiscussionCount() inside of the condition block?

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.

@askvortsov1
Copy link
Member

Agreed.

@franzliedke
Copy link
Contributor

@clarkwinkelmann Do you mean the if ($post->number == 1) block? That would be before the discussion save, so the result would be different, right?

@luceos luceos removed their request for review June 7, 2020 07:37
@clarkwinkelmann
Copy link
Member

clarkwinkelmann commented Jun 16, 2020

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.

@askvortsov1
Copy link
Member

I like the second one

@askvortsov1
Copy link
Member

@imzhi would you be interested in updating this PR as discussed above?

@imzhi imzhi force-pushed the approve-update-usermeta branch from 1cac468 to 66f42d3 Compare February 19, 2021 02:08
@imzhi
Copy link
Contributor Author

imzhi commented Feb 19, 2021

@askvortsov1 A new commit was finished based on the discussion.

@askvortsov1 askvortsov1 requested a review from SychO9 February 19, 2021 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants