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

Fix total votes scope to remove redundant DB query #6

Merged
merged 1 commit into from
Aug 11, 2022

Conversation

gordanielyan
Copy link
Contributor

If you try to get something like
Idea::withTotalVotes()->get()
the attribute total_votes can be null if there are no votes, which will result in additional query because of this fallback

return (int) $this->attributes['total_votes'] ?? $this->totalVotes();

i suggest to use COALESCE to make it zero when no records are found

@overtrue overtrue merged commit d1290b6 into overtrue:master Aug 11, 2022
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.

None yet

2 participants