Permalink
Browse files

PERF: memoize to avoid N+1 query in category page

  • Loading branch information...
SamSaffron committed Oct 2, 2015
1 parent 55c0f6a commit 6246dd0aa22bb0053cc0fb1876713e8d08db829d
Showing with 2 additions and 1 deletion.
  1. +2 −1 app/models/category.rb
@@ -382,7 +382,8 @@ def self.find_by_email(email)
end

def has_children?
id && Category.where(parent_category_id: id).exists?
@has_children ||= (id && Category.where(parent_category_id: id).exists?) ? :true : :false
@has_children == :true

This comment has been minimized.

@ptolts

ptolts Nov 26, 2015

Why use a symbol vs bool?

This comment has been minimized.

@daniloisr

daniloisr Jan 15, 2016

it's not possible to memoize (||=) bool false value

This comment has been minimized.

@ptolts

ptolts Jan 15, 2016

Ahh yes. Duh.

Thanks

end

def uncategorized?

0 comments on commit 6246dd0

Please sign in to comment.