fixed 项目列表查询count优化

This commit is contained in:
“xxq250” 2022-11-08 17:18:04 +08:00
parent abfb62f342
commit 7cc9d207b6
3 changed files with 6 additions and 5 deletions

View File

@ -39,8 +39,9 @@ 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?
# ps = ProjectStatistic.first
# ps.common_projects_count + ps.mirror_projects_count unless ps.blank?
@projects.total_count
else
cate = ProjectCategory.find_by(id: category_id)
cate&.projects_count || 0

View File

@ -17,7 +17,7 @@ class Projects::ListQuery < ApplicationQuery
sort = params[:sort_by] || "updated_on"
sort_direction = params[:sort_direction] || "desc"
collection = optimize_sorting(collection, sort) if params[:category_id].present?
# collection = optimize_sorting(collection, sort) if params[:category_id].present?
custom_sort(collection, sort, sort_direction)
# scope = scope.reorder("projects.#{sort} #{sort_direction}")

View File

@ -1,4 +1,4 @@
json.total_count @projects.total_count
json.total_count @total_count
json.projects @projects do |project|
# json.partial! "/projects/project_detail", project: project
json.id project.id
@ -22,7 +22,7 @@ json.projects @projects do |project|
project_educoder = project.project_educoder
json.name project_educoder&.owner
json.login project_educoder&.repo_name.split('/')[0]
json.image_url render_educoder_avatar_url(project.project_educoder)
# json.image_url render_educoder_avatar_url(project.project_educoder)
else
user = project.owner
json.type user.type