R
Richard Schneeman
Hey, i’m running into an N+1 problem, but i don't exactly know how to
:include in this situation. (controller code is at the bottom).
I'm trying to find all of the highest ranked definitions, and then
render their associated phrases.
A Phrase has many definitions. A Definition has many children
I already have all the info i need stored in @definitions, so this
should only require one SQL call, but unfortunately this line:
@Phrases << definition.phraseinclude => [:definitions => :children])
Doesn’t actually work.
Below is my controller code. Rails 2.1.0, Ruby 1.8.6…Thanks ahead of
time
def index
@definitions = Definition.findall, :include => [:children,
hrase], :limit => 10, rder => 'rank DESC')
@Phrases = []
for definition in @definitions
@Phrases << definition.phraseinclude => [:definitions =>
:children])
end
@Phrases = @Phrases.uniq
if @Phrases != nil
@new_phrases = @Phrases.paginatepage => params[age], rder
=> 'word ASC', er_page => 5)
end ## if @phrase !=nil
end ##def index
The full capture can be found under my <a href
="https://tuneup.fiveruns.com/runs/699"> Five Runs Account </a>
If you have any suggestions i would love for my main page to not take
5000 milliseconds to load : )
:include in this situation. (controller code is at the bottom).
I'm trying to find all of the highest ranked definitions, and then
render their associated phrases.
A Phrase has many definitions. A Definition has many children
I already have all the info i need stored in @definitions, so this
should only require one SQL call, but unfortunately this line:
@Phrases << definition.phraseinclude => [:definitions => :children])
Doesn’t actually work.
Below is my controller code. Rails 2.1.0, Ruby 1.8.6…Thanks ahead of
time
def index
@definitions = Definition.findall, :include => [:children,
hrase], :limit => 10, rder => 'rank DESC')
@Phrases = []
for definition in @definitions
@Phrases << definition.phraseinclude => [:definitions =>
:children])
end
@Phrases = @Phrases.uniq
if @Phrases != nil
@new_phrases = @Phrases.paginatepage => params[age], rder
=> 'word ASC', er_page => 5)
end ## if @phrase !=nil
end ##def index
The full capture can be found under my <a href
="https://tuneup.fiveruns.com/runs/699"> Five Runs Account </a>
If you have any suggestions i would love for my main page to not take
5000 milliseconds to load : )