From 2302ad9b88aa4752f4b310783984f4891d20457b Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Mar 2023 16:45:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=8C=BA?= =?UTF-8?q?=E5=9D=97=E7=A1=AE=E6=9D=83=E8=B4=A1=E7=8C=AE=E8=80=85=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 18 ++++++++++++------ lib/tasks/sync_mindspore_contributors.rake | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 1d98b17f4..8610f5f16 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/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", From 64d9d21457f2a9b25c0a8a59e08df32af03bad54 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Mar 2023 17:01:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=8C=BA?= =?UTF-8?q?=E5=9D=97=E7=A1=AE=E6=9D=83=E8=B4=A1=E7=8C=AE=E8=80=85=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 4 ++-- app/views/repositories/_contributor.json.jbuilder | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 8610f5f16..d7fdb51ac 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -169,8 +169,8 @@ class RepositoriesController < ApplicationController end def contributors - cache_result = $redis_cache.get("ProjectSpecialCommit:#{@project.id}") - if cache_result.present? + @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 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"]