项目列表默认查询时count性能问题处理, not_category_count
This commit is contained in:
		
							parent
							
								
									643fb163d9
								
							
						
					
					
						commit
						c58880a4d3
					
				| 
						 | 
					@ -1,5 +1,4 @@
 | 
				
			||||||
class ProjectCategoriesController < ApplicationController
 | 
					class ProjectCategoriesController < ApplicationController
 | 
				
			||||||
  before_action :re_total_count, only: [:pinned_index]
 | 
					 | 
				
			||||||
  def index
 | 
					  def index
 | 
				
			||||||
    # @project_categories = ProjectCategory.search(params[:name]).without_content
 | 
					    # @project_categories = ProjectCategory.search(params[:name]).without_content
 | 
				
			||||||
    q = ProjectCategory.ransack(name_cont: params[:name])
 | 
					    q = ProjectCategory.ransack(name_cont: params[:name])
 | 
				
			||||||
| 
						 | 
					@ -15,11 +14,4 @@ class ProjectCategoriesController < ApplicationController
 | 
				
			||||||
    # projects = Project.no_anomory_projects.visible
 | 
					    # projects = Project.no_anomory_projects.visible
 | 
				
			||||||
    # @category_group_list = projects.joins(:project_category).group("project_categories.id", "project_categories.name").size
 | 
					    # @category_group_list = projects.joins(:project_category).group("project_categories.id", "project_categories.name").size
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					 | 
				
			||||||
  def re_total_count
 | 
					 | 
				
			||||||
    # 未分类项目与其他放在一起
 | 
					 | 
				
			||||||
    other_category  = ProjectCategory.find_by(name: "其它")
 | 
					 | 
				
			||||||
    other_count = Project.where(project_category_id: [15,nil]).count
 | 
					 | 
				
			||||||
    other_category.update(projects_count:  other_count)
 | 
					 | 
				
			||||||
  end
 | 
					 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,7 +43,8 @@ class ProjectsController < ApplicationController
 | 
				
			||||||
    @total_count =
 | 
					    @total_count =
 | 
				
			||||||
      if category_id.blank? && params[:search].blank? && params[:topic_id].blank?
 | 
					      if category_id.blank? && params[:search].blank? && params[:topic_id].blank?
 | 
				
			||||||
        # 默认查询时count性能问题处理
 | 
					        # 默认查询时count性能问题处理
 | 
				
			||||||
        ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count
 | 
					        not_category_count = Project.where(project_category_id: nil).count
 | 
				
			||||||
 | 
					        ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count + not_category_count
 | 
				
			||||||
      elsif params[:search].present? || params[:topic_id].present?
 | 
					      elsif params[:search].present? || params[:topic_id].present?
 | 
				
			||||||
        @projects.total_count
 | 
					        @projects.total_count
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue