From 4b1092372319ddd7849d570955f784bb7776ff94 Mon Sep 17 00:00:00 2001 From: Washington Botelho Date: Mon, 8 Aug 2022 18:55:02 -0300 Subject: [PATCH] ref: uses exists over find_by for optimization --- lib/rating/models/rating/extension.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/rating/models/rating/extension.rb b/lib/rating/models/rating/extension.rb index 6816fe2..df87320 100644 --- a/lib/rating/models/rating/extension.rb +++ b/lib/rating/models/rating/extension.rb @@ -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)