Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7430649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:10:32+00:00 2026-05-29T09:10:32+00:00

My app is slowed down by N+1 queries. I’m using the will_paginate gem with

  • 0

My app is slowed down by N+1 queries. I’m using the will_paginate gem with Rails 3.1 and Oracle 11.2.

Normally, the solution would be to use ActiveRecord#includes() to read in child records at the same time that I fetch the parent records, but every attempt I’ve made seems to either not work with will_paginate, or end up fetching the whole database into memory. I tried making a named scope, but it seems scopes are fetched immediately when called, not lazily.

class Parent < ActiveRecord::Base
  has_many :children, :dependent => :delete_all
end

class Child < ActiveRecord::Base
  belongs_to :parent
end

class ParentsController < ApplicationController
def index
  @parents = Parent.paginate page: params[:page], order: 'id', per_page: 32
end

Index.html.erb contains, among other things,

<%= page_entries_info @parents %>
<%= will_paginate @parents, :container => false %>
<% @parents.each do |parent| %>
<%= parent.call_to_method_that_uses_children_association_causing_N+1_query %>
<% end %>

If I can’t afford to fetch the whole database into memory, and don’t want to fetch a page of parents, followed by N child fetches, are there other options besides abandoning will_paginate?

Also, is there any substantial documentation for will_paginate? The info on github is pretty sparse. For example, what does the :container option to will_paginate method mean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:10:33+00:00Added an answer on May 29, 2026 at 9:10 am
    Parent.includes(:children).paginate(:page => params[:page], :per_page => 30)
    

    From another question that is similar to yours

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This pertains to Google App Engine, using Java. (threadsafe in this scenario would be
App Engine only allows you to use these formats for XMPP addresses: app-id@appspot.com anything@app-id.appspotchat.com
Our app (already deployed) is using an Access/Jet database. The upcoming version of our
When I call hreq.getSession().invalidate(); app engine slows down tremendously. I looked at appstats and
I'm running a rails 3.1 app on Heroku Cedar stack which supports the asset
i have an app in which i am using a sqlite db of PRAGMA
I'm creating an iPhone app that will pull data down from a Web API,
I have an app that I pack into binary form using PerlApp for distribution.
I installed the active_admin gem in a working rails application. After doing this, the
So this is my problem. I used Capistrano to deploy my Rails 3 app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.