From 43c683e83f3fae333c9434e38954862383f47895 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 2 Nov 2021 11:27:17 +0800 Subject: [PATCH] fix: contributor load cache data --- .../repositories/_contributor.json.jbuilder | 16 ++++++++++++++++ .../repositories/contributors.json.jbuilder | 12 +----------- app/views/repositories/detail.json.jbuilder | 12 +----------- 3 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 app/views/repositories/_contributor.json.jbuilder diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder new file mode 100644 index 000000000..56fa9ce86 --- /dev/null +++ b/app/views/repositories/_contributor.json.jbuilder @@ -0,0 +1,16 @@ +user = $redis_cache.hgetall("v2-owner-common:#{contributor["login"]}-#{contributor["email"]}") +if user.blank? + json.contributions contributor["contributions"] + # json.gid contributor["id"] + json.login contributor["login"] + json.type nil + json.name contributor["login"] + json.image_url User::Avatar.get_letter_avatar_url(contributor["login"]) +else + json.contributions contributor["contributions"] + # json.gid contributor["id"] + json.login user["login"] + json.type user["type"] + json.name user["name"] + json.image_url user["avatar_url"] +end diff --git a/app/views/repositories/contributors.json.jbuilder b/app/views/repositories/contributors.json.jbuilder index 9165cf948..fa52475a5 100644 --- a/app/views/repositories/contributors.json.jbuilder +++ b/app/views/repositories/contributors.json.jbuilder @@ -1,16 +1,6 @@ total_count = @contributors.size json.contributors @contributors.each do |contributor| - user = User.find_by(gitea_uid: contributor["id"]) - if contributor["login"] == "root" - total_count -= 1 - next - end - json.contributions contributor["contributions"] - # json.gid contributor["id"] - json.login user.login - json.type user&.type - json.name user.real_name - json.image_url url_to_avatar(user) + json.partial! 'contributor', locals: { contributor: contributor } end json.total_count total_count diff --git a/app/views/repositories/detail.json.jbuilder b/app/views/repositories/detail.json.jbuilder index c489cf47a..20faea44c 100644 --- a/app/views/repositories/detail.json.jbuilder +++ b/app/views/repositories/detail.json.jbuilder @@ -56,17 +56,7 @@ json.tags_count @result[:branch_tag_total_count]['tag_count'] || 0 json.contributors do total_count = @result[:contributor].size json.list @result[:contributor].each do |contributor| - user = User.find_by(gitea_uid: contributor["id"]) - if contributor["login"] == "root" || user.nil? - total_count -= 1 - next - end - json.contributions contributor["contributions"] - json.gid contributor["id"] - json.login user.login - json.type user&.type - json.name user.real_name - json.image_url url_to_avatar(user) + json.partial! 'contributor', locals: { contributor: contributor } end json.total_count total_count end