From 9da61bd69e23974fc217a934a9db3048a728d153 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 7 Mar 2023 16:34:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=9F=A5=E8=AF=A2=E6=97=B6count=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 053c89e02..440379ac3 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -39,13 +39,14 @@ class ProjectsController < ApplicationController category_id = params[:category_id] @total_count = - if category_id.blank? - # ps = ProjectStatistic.first - # ps.common_projects_count + ps.mirror_projects_count unless ps.blank? + if category_id.blank? && params[:search].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 + elsif params[:search].present? @projects.total_count else - cate = ProjectCategory.find_by(id: category_id) - cate&.projects_count || 0 + cate = ProjectCategory.find_by(id: category_id) + cate&.projects_count || 0 end end