You are getting N+1
queries due to the scope get_all
which executes a query for items
of each category
.
The actual solution to the problem of slow load time depends on which query is making it slow. See the server query logs to figure that out and post them if you need help.
The N+1
query problem can be solved by getting the count in Ruby
itself like this:
category.items.select{|i| !i.deleted}.count