mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-04-29 03:16:21 -04:00
Eager loading for frequently-accessed/database-heavy pages
This commit is contained in:
@@ -6,7 +6,7 @@ class CropsController < ApplicationController
|
||||
# GET /crops
|
||||
# GET /crops.json
|
||||
def index
|
||||
@crops = Crop.paginate(:page => params[:page])
|
||||
@crops = Crop.includes(:scientific_names, {:plantings => :photos}).paginate(:page => params[:page])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.haml
|
||||
@@ -18,7 +18,7 @@ class CropsController < ApplicationController
|
||||
# GET /crops/1
|
||||
# GET /crops/1.json
|
||||
def show
|
||||
@crop = Crop.find(params[:id])
|
||||
@crop = Crop.includes(:scientific_names, {:plantings => :photos}).find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.haml
|
||||
|
||||
@@ -6,10 +6,11 @@ class PlantingsController < ApplicationController
|
||||
# GET /plantings
|
||||
# GET /plantings.json
|
||||
def index
|
||||
@plantings = Planting.paginate(:page => params[:page])
|
||||
@owner = Member.find_by_slug(params[:owner])
|
||||
if @owner
|
||||
@plantings = @owner.plantings.paginate(:page => params[:page])
|
||||
@plantings = @owner.plantings.includes(:owner, :crop, :garden).paginate(:page => params[:page])
|
||||
else
|
||||
@plantings = Planting.includes(:owner, :crop, :garden).paginate(:page => params[:page])
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
@@ -22,7 +23,7 @@ class PlantingsController < ApplicationController
|
||||
# GET /plantings/1
|
||||
# GET /plantings/1.json
|
||||
def show
|
||||
@planting = Planting.find(params[:id])
|
||||
@planting = Planting.includes(:owner, :crop, :garden, :photos).find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
|
||||
@@ -7,10 +7,11 @@ class PostsController < ApplicationController
|
||||
# GET /posts.json
|
||||
|
||||
def index
|
||||
@posts = Post.paginate(:page => params[:page])
|
||||
@author = Member.find_by_slug(params[:author])
|
||||
if @author
|
||||
@posts = @author.posts.paginate(:page => params[:page])
|
||||
@posts = @author.posts.includes(:author, { :comments => :author }).paginate(:page => params[:page])
|
||||
else
|
||||
@posts = Post.includes(:author, { :comments => :author }).paginate(:page => params[:page])
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
@@ -23,8 +24,7 @@ class PostsController < ApplicationController
|
||||
# GET /posts/1
|
||||
# GET /posts/1.json
|
||||
def show
|
||||
@post = Post.find(params[:id])
|
||||
@comments = @post.comments
|
||||
@post = Post.includes(:author, { :comments => :author }).find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.haml
|
||||
|
||||
@@ -6,10 +6,11 @@ class SeedsController < ApplicationController
|
||||
# GET /seeds
|
||||
# GET /seeds.json
|
||||
def index
|
||||
@seeds = Seed.paginate(:page => params[:page])
|
||||
@owner = Member.find_by_slug(params[:owner])
|
||||
if @owner
|
||||
@seeds = @owner.seeds.paginate(:page => params[:page])
|
||||
@seeds = @owner.seeds.includes(:owner, :crop).paginate(:page => params[:page])
|
||||
else
|
||||
@seeds = Seed.includes(:owner, :crop).paginate(:page => params[:page])
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
|
||||
Reference in New Issue
Block a user