From 9f269189a4f61df35ae55374646ec8f51f969d04 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 29 Aug 2024 16:00:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AE=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=94=AF=E6=8C=81=E5=A4=9A=E4=B8=AA=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E6=9F=A5=E8=AF=A2,=20=E5=AE=9A=E5=88=B6?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=A0=87=E7=AD=BE=E5=8F=AF=E6=9F=A5=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E7=A7=81=E6=9C=89=E4=BB=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queries/projects/list_query.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 737cd7c2d..931f26145 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -77,7 +77,10 @@ class Projects::ListQuery < ApplicationQuery end def by_project_topic(items) - if params[:topic_name].present? + 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? items.with_project_topic_name(params[:topic_name].to_s.split(",")) else items.with_project_topic(params[:topic_id]) From 39f234cc06c95eb62a16977df13c8f107e0dd3c6 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 29 Aug 2024 16:18:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fixed=20=E4=B8=AA=E4=BA=BA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=88=97=E8=A1=A8=E6=9D=A1=E4=BB=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A0=87=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