FIX: better memoize of policy_group (#9)

FIX: better memoize of policy_group (#9)

Based on @eviltrout comment this is a better approach (https://jtway.co/how-to-memoize-false-and-nil-values-fe28b8ede9f8)

diff --git a/app/models/post_policy.rb b/app/models/post_policy.rb
index f6462e6..0633289 100644
--- a/app/models/post_policy.rb
+++ b/app/models/post_policy.rb
@@ -29,12 +29,10 @@ class PostPolicy < ActiveRecord::Base
   end
 
   def policy_group
-    return @policy_group == :nil ? nil : @policy_group if @policy_group
-    @policy_group = :nil
-
+    return @policy_group if defined?(@policy_group)
     @policy_group = Group
       .where('user_count < ?', SiteSetting.policy_max_group_size)
       .where('id in (SELECT group_id FROM post_policies WHERE post_id = ?)', post.id)
-      .first || :nil
+      .first
   end
 end

GitHub sha: 4b227c40