Eager load route & namespace in `Explore::ProjectsController`
This commit is contained in:
		
							parent
							
								
									9cca8c0060
								
							
						
					
					
						commit
						901e70fba1
					
				| 
						 | 
					@ -2,7 +2,7 @@ class Explore::ProjectsController < Explore::ApplicationController
 | 
				
			||||||
  include FilterProjects
 | 
					  include FilterProjects
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def index
 | 
					  def index
 | 
				
			||||||
    @projects = ProjectsFinder.new.execute(current_user)
 | 
					    @projects = load_projects
 | 
				
			||||||
    @tags = @projects.tags_on(:tags)
 | 
					    @tags = @projects.tags_on(:tags)
 | 
				
			||||||
    @projects = @projects.tagged_with(params[:tag]) if params[:tag].present?
 | 
					    @projects = @projects.tagged_with(params[:tag]) if params[:tag].present?
 | 
				
			||||||
    @projects = @projects.where(visibility_level: params[:visibility_level]) if params[:visibility_level].present?
 | 
					    @projects = @projects.where(visibility_level: params[:visibility_level]) if params[:visibility_level].present?
 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,8 @@ class Explore::ProjectsController < Explore::ApplicationController
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def trending
 | 
					  def trending
 | 
				
			||||||
    @projects = filter_projects(Project.trending)
 | 
					    @projects = load_projects(Project.trending)
 | 
				
			||||||
 | 
					    @projects = filter_projects(@projects)
 | 
				
			||||||
    @projects = @projects.sort(@sort = params[:sort])
 | 
					    @projects = @projects.sort(@sort = params[:sort])
 | 
				
			||||||
    @projects = @projects.page(params[:page])
 | 
					    @projects = @projects.page(params[:page])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,7 +37,7 @@ class Explore::ProjectsController < Explore::ApplicationController
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def starred
 | 
					  def starred
 | 
				
			||||||
    @projects = ProjectsFinder.new.execute(current_user)
 | 
					    @projects = load_projects
 | 
				
			||||||
    @projects = filter_projects(@projects)
 | 
					    @projects = filter_projects(@projects)
 | 
				
			||||||
    @projects = @projects.reorder('star_count DESC')
 | 
					    @projects = @projects.reorder('star_count DESC')
 | 
				
			||||||
    @projects = @projects.page(params[:page])
 | 
					    @projects = @projects.page(params[:page])
 | 
				
			||||||
| 
						 | 
					@ -50,4 +51,11 @@ class Explore::ProjectsController < Explore::ApplicationController
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  protected
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def load_projects(base_scope = nil)
 | 
				
			||||||
 | 
					    base_scope ||= ProjectsFinder.new.execute(current_user)
 | 
				
			||||||
 | 
					    base_scope.includes(:route, namespace: :route)
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue