仓库语言缓存随着项目数变化,计算调整

This commit is contained in:
xxq250 2023-04-27 18:11:00 +08:00
parent ba344e76ba
commit 8198b347e7
1 changed files with 3 additions and 2 deletions

View File

@ -88,15 +88,16 @@ class Organizations::OrganizationsController < Organizations::BaseController
projects = @organization.projects projects = @organization.projects
projects_count = @organization.projects.count projects_count = @organization.projects.count
languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}/#{projects_count}", :expires_in => 1.days) do languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}/#{projects_count}/2023", :expires_in => 1.days) do
total_languages(projects) total_languages(projects)
end end
languages_hash = languages_hash.sort { |x, y| y[1] <=> x[1] } languages_hash = languages_hash.sort { |x, y| y[1] <=> x[1] }
sort_hash = Hash[*languages_hash.flatten] sort_hash = Hash[*languages_hash.flatten]
total_byte_size = sort_hash.values.sum
# Rails.logger.info "languages_hash=============#{sort_hash}" # Rails.logger.info "languages_hash=============#{sort_hash}"
sort_hash= sort_hash.transform_values { |v| sort_hash= sort_hash.transform_values { |v|
ActionController::Base.helpers.number_to_percentage((v / projects_count), precision: 1) ActionController::Base.helpers.number_to_percentage((v * 100 / total_byte_size), precision: 1)
}.select { |k, v| v != "0.0%" } }.select { |k, v| v != "0.0%" }
render json: sort_hash render json: sort_hash
end end