项目列表默认查询时count性能问题处理

This commit is contained in:
2024-04-19 17:21:01 +08:00
parent edfc540469
commit 643fb163d9
2 changed files with 9 additions and 2 deletions

View File

@@ -43,8 +43,7 @@ class ProjectsController < ApplicationController
@total_count =
if category_id.blank? && params[:search].blank? && params[:topic_id].blank?
# 默认查询时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
@projects.total_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
elsif params[:search].present? || params[:topic_id].present?
@projects.total_count
else