learnenough / rails_tutorial_sample_app_7th_ed

The reference sample app for the Ruby on Rails Tutorial (7th edition) by Michael Hartl
Other
75 stars 52 forks source link

Update UsersController to fix microposts pagination #16

Closed petecheslock closed 10 months ago

petecheslock commented 10 months ago

In the existing code, the show action in the UsersController fetches a user's microposts and eagerly loads associated images using includes(:user, image_attachment: :blob). While this approach ensures that microposts and their associated images are loaded efficiently, it can result in unnecessary database queries and increased loading times when there are a large number of microposts.

We have removed the .includes(:user, image_attachment: :blob) portion when fetching microposts for a user. Instead, we now use @user.microposts.paginate(page: params[:page]) for micropost retrieval. This change eliminates the eager loading of associated images for now.