diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 1d98b17f4..d7fdb51ac 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -169,12 +169,18 @@ class RepositoriesController < ApplicationController end def contributors - if params[:filepath].present? || @project.educoder? - @contributors = [] - else - result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]}) - @total_count = result[:total_count] - @contributors = result.is_a?(Hash) ? result[:body] : [] + @cache_result = $redis_cache.get("ProjectSpecialCommit:#{@project.id}") + if @cache_result.present? + @total_count = Project.mindspore_contributors.size + @contributors = kaminari_array_paginate(Project.mindspore_contributors) + else + if params[:filepath].present? || @project.educoder? + @contributors = [] + else + result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]}) + @total_count = result[:total_count] + @contributors = result.is_a?(Hash) ? result[:body] : [] + end end rescue @contributors = [] diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index c8b2db373..dca0a93bf 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -6,6 +6,12 @@ if user.blank? json.type nil json.name contributor["login"] json.image_url User::Avatar.get_letter_avatar_url(contributor["login"]) + if @cache_result.present? + db_user = User.find_by_id(contributor["id"]) + if db_user.present? + json.contribution_perc db_user.contribution_perc(project) + end + end else json.contributions contributor["contributions"] # json.gid contributor["id"] diff --git a/lib/tasks/sync_mindspore_contributors.rake b/lib/tasks/sync_mindspore_contributors.rake index 0c8ace17c..564ee38eb 100644 --- a/lib/tasks/sync_mindspore_contributors.rake +++ b/lib/tasks/sync_mindspore_contributors.rake @@ -65,7 +65,7 @@ namespace :sync_mindspore do total_contributions = contributions.sum{|i| i["contributions"]} contributions.each do |con| cont_balance = Float(con["contributions"]*9900/total_contributions).round(0) - token_balance << [con["id"], cont_balance] if cont_balance > 0 + token_balance << [con["id"].to_s, cont_balance] if cont_balance > 0 end params = { "request-type": "create repo",