From eba672f39a4330fb692b058a5f1d91c39ca9f8d8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 29 Oct 2021 19:38:49 +0800 Subject: [PATCH 1/2] fix: user popular project nil --- app/views/user_rank/_detail.json.jbuilder | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/views/user_rank/_detail.json.jbuilder b/app/views/user_rank/_detail.json.jbuilder index 54afea5c..11eda3fc 100644 --- a/app/views/user_rank/_detail.json.jbuilder +++ b/app/views/user_rank/_detail.json.jbuilder @@ -1,15 +1,19 @@ owner_common = $redis_cache.hgetall("v2-owner-common:#{item[0]}") popular_project = $redis_cache.zrevrange("v2-user-project-rank:#{item[0]}", 0, 1, withscores: true)[0] -popular_project_common = $redis_cache.hgetall("v2-project-common:#{popular_project[0]}") json.id item[0] json.score item[1] json.name owner_common["name"] json.type owner_common["type"] json.login owner_common["login"] json.avatar_url owner_common["avatar_url"] -json.project do - json.id popular_project[0] - json.name popular_project_common["name"] - json.identifier popular_project_common["identifier"] - json.description popular_project_common["description"] +if popular_project.blank? + json.project nil +else + popular_project_common = $redis_cache.hgetall("v2-project-common:#{popular_project[0]}") + json.project do + json.id popular_project[0] + json.name popular_project_common["name"] + json.identifier popular_project_common["identifier"] + json.description popular_project_common["description"] + end end \ No newline at end of file From de2399a0a1985b4640aea1a33993aeeceec82345 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 29 Oct 2021 19:54:58 +0800 Subject: [PATCH 2/2] fix: project category load slowly --- app/controllers/admins/project_categories_controller.rb | 2 +- app/views/admins/project_categories/_list.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admins/project_categories_controller.rb b/app/controllers/admins/project_categories_controller.rb index 3b5065a1..8b1dd1f7 100644 --- a/app/controllers/admins/project_categories_controller.rb +++ b/app/controllers/admins/project_categories_controller.rb @@ -5,7 +5,7 @@ class Admins::ProjectCategoriesController < Admins::BaseController def index sort_by = ProjectCategory.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc' - q = ProjectCategory.includes(:projects).ransack(name_cont: params[:name]) + q = ProjectCategory.ransack(name_cont: params[:name]) project_categories = q.result(distinct: true).order("#{sort_by} #{sort_direction}") @project_categories = paginate(project_categories) diff --git a/app/views/admins/project_categories/_list.html.erb b/app/views/admins/project_categories/_list.html.erb index 1a460a48..1a1626bc 100644 --- a/app/views/admins/project_categories/_list.html.erb +++ b/app/views/admins/project_categories/_list.html.erb @@ -20,7 +20,7 @@ <%= project_category.pinned_index == 0 ? "" : "√" %> <%= project_category.projects_count %> - <%= project_category.projects.where(is_pinned: true).size %> + <%= project_category.projects.select(:id).where(is_pinned: true).size %> <%= project_category.created_at&.strftime('%Y-%m-%d %H:%M') %> <%= link_to "编辑", edit_admins_project_category_path(project_category), remote: true, class: "action" %>