From c58880a4d33f42da178b5974d79b85b92e68b6c4 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 22 Apr 2024 08:44:20 +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,=20not=5Fcategory=5Fcount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/project_categories_controller.rb | 8 -------- app/controllers/projects_controller.rb | 3 ++- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/app/controllers/project_categories_controller.rb b/app/controllers/project_categories_controller.rb index 08ff0d61b..f6b3cbc9d 100644 --- a/app/controllers/project_categories_controller.rb +++ b/app/controllers/project_categories_controller.rb @@ -1,5 +1,4 @@ class ProjectCategoriesController < ApplicationController - before_action :re_total_count, only: [:pinned_index] def index # @project_categories = ProjectCategory.search(params[:name]).without_content q = ProjectCategory.ransack(name_cont: params[:name]) @@ -15,11 +14,4 @@ class ProjectCategoriesController < ApplicationController # projects = Project.no_anomory_projects.visible # @category_group_list = projects.joins(:project_category).group("project_categories.id", "project_categories.name").size 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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index eb242475e..a47dc4bfb 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -43,7 +43,8 @@ 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 + 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? @projects.total_count else