Merge pull request '用户排行榜数据缺失报错问题' (#231) from yystopf/forgeplus:hh_project_rank into develop

This commit is contained in:
yystopf 2021-11-02 09:59:05 +08:00
commit 2273b4817e
3 changed files with 12 additions and 8 deletions

View File

@ -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)

View File

@ -20,7 +20,7 @@
</td>
<td><%= project_category.pinned_index == 0 ? "" : "√" %></td>
<td><%= project_category.projects_count %></td>
<td><%= project_category.projects.where(is_pinned: true).size %></td>
<td><%= project_category.projects.select(:id).where(is_pinned: true).size %></td>
<td><%= project_category.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td class="action-container">
<%= link_to "编辑", edit_admins_project_category_path(project_category), remote: true, class: "action" %>

View File

@ -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