ref: uses exists over find_by for optimization

main
Washington Botelho 2022-08-08 18:55:02 -03:00
parent ce695da199
commit 4b10923723
No known key found for this signature in database
GPG Key ID: 5DE4F42A8F073617
1 changed files with 1 additions and 2 deletions

View File

@ -20,9 +20,8 @@ module Rating
Rate.rate_for author: self, extra_scopes: extra_scopes, resource: resource, scopeable: scope
end
# TODO: use exists for performance
def rated?(resource, extra_scopes: {}, scope: nil)
!rate_for(resource, extra_scopes: extra_scopes, scope: scope).nil?
Rate.exists?(extra_scopes.merge(author: self, resource: resource, scopeable: scope))
end
def rates(extra_scopes: {}, scope: nil)