From 39f234cc06c95eb62a16977df13c8f107e0dd3c6 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 29 Aug 2024 16:18:59 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E4=B8=AA=E4=BA=BA=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=9D=A1=E4=BB=B6=E5=A2=9E=E5=8A=A0=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 4 ++-- app/queries/projects/list_query.rb | 5 +---- app/services/users/project_service.rb | 9 +++++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ab7f1cdc6..5e036ff51 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -43,11 +43,11 @@ class ProjectsController < ApplicationController category_id = params[:category_id] @total_count = - if category_id.blank? && params[:search].blank? && params[:topic_id].blank? + if category_id.blank? && params[:search].blank? && params[:topic_id].blank? && params[:topic_name].blank? # 默认查询时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? || params[:topic_name].present? @projects.total_count else cate = ProjectCategory.find_by(id: category_id) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 931f26145..737cd7c2d 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -77,10 +77,7 @@ class Projects::ListQuery < ApplicationQuery end def by_project_topic(items) - if params[:topic_name].present? && @current_user_id.present? - Project.visible.where(status: 1).with_project_topic_name(params[:topic_name].to_s.split(",")) - .or(Project.is_private.with_project_topic_name(params[:topic_name].to_s.split(",")).where(user_id: @current_user_id)) - elsif params[:topic_name].present? + if params[:topic_name].present? items.with_project_topic_name(params[:topic_name].to_s.split(",")) else items.with_project_topic(params[:topic_id]) diff --git a/app/services/users/project_service.rb b/app/services/users/project_service.rb index f08b96009..86b2e9bb2 100644 --- a/app/services/users/project_service.rb +++ b/app/services/users/project_service.rb @@ -20,6 +20,7 @@ class Users::ProjectService projects = category_filter(projects) projects = status_filter(projects) + projects = by_project_topic(projects) custom_sort(projects, params[:sort_by], params[:sort_direction]) end @@ -45,6 +46,14 @@ class Users::ProjectService end end + def by_project_topic(items) + if params[:topic_name].present? + items.with_project_topic_name(params[:topic_name].to_s.split(",")) + else + items.with_project_topic(params[:topic_id]) + end + end + def self_or_admin? User.current.id == user.id || User.current.admin? end