diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c37fd59da..01ffa41f1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -442,6 +442,14 @@ module ApplicationHelper User.find_by(gitea_uid: gitea_uid) end + def find_user_in_redis_cache(login, email) + $redis_cache.hgetall("v2-owner-common:#{login}-#{email}") + end + + def find_user_in_redis_cache_by_id(id) + $redis_cache.hgetall("v2-owner-common:#{id}") + end + def render_base64_decoded(str) return nil if str.blank? Base64.decode64 str diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 1096d1d21..fe5a636eb 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -35,6 +35,10 @@ module RepositoriesHelper end end + def render_cache_commit_author(author_json) + find_user_in_redis_cache(author_json['name'], author_json['email']) + end + def readme_render_decode64_content(str, path) return nil if str.blank? begin diff --git a/app/views/projects/branches.json.jbuilder b/app/views/projects/branches.json.jbuilder index ad4f4328a..c7c2025b3 100644 --- a/app/views/projects/branches.json.jbuilder +++ b/app/views/projects/branches.json.jbuilder @@ -12,10 +12,10 @@ json.array! @branches do |branch| json.timestamp render_unix_time(branch['commit']['timestamp']) json.time_from_now time_from_now(branch['commit']['timestamp']) json.author do - json.partial! 'repositories/commit_author', user: render_commit_author(branch['commit']['author']), name: branch['commit']['author']['name'] + json.partial! 'repositories/commit_author', user: render_cache_commit_author(branch['commit']['author']), name: branch['commit']['author']['name'] end json.committer do - json.partial! 'repositories/commit_author', user: render_commit_author(branch['commit']['committer']), name: branch['commit']['committer']['name'] + json.partial! 'repositories/commit_author', user: render_cache_commit_author(branch['commit']['committer']), name: branch['commit']['committer']['name'] end end end diff --git a/app/views/projects/branches_slice.json.jbuilder b/app/views/projects/branches_slice.json.jbuilder index 31c662a13..963bca0a8 100644 --- a/app/views/projects/branches_slice.json.jbuilder +++ b/app/views/projects/branches_slice.json.jbuilder @@ -14,10 +14,10 @@ json.array! @branches_slice do |branch_slice| json.timestamp render_unix_time(branch['commit']['timestamp']) json.time_from_now time_from_now(branch['commit']['timestamp']) json.author do - json.partial! 'repositories/commit_author', user: render_commit_author(branch['commit']['author']), name: branch['commit']['author']['name'] + json.partial! 'repositories/commit_author', user: render_cache_commit_author(branch['commit']['author']), name: branch['commit']['author']['name'] end json.committer do - json.partial! 'repositories/commit_author', user: render_commit_author(branch['commit']['committer']), name: branch['commit']['committer']['name'] + json.partial! 'repositories/commit_author', user: render_cache_commit_author(branch['commit']['committer']), name: branch['commit']['committer']['name'] end end end diff --git a/app/views/pull_requests/_commit.json.jbuilder b/app/views/pull_requests/_commit.json.jbuilder index 7a9232efe..52b776008 100644 --- a/app/views/pull_requests/_commit.json.jbuilder +++ b/app/views/pull_requests/_commit.json.jbuilder @@ -1,11 +1,9 @@ json.author do - author = User.find_by(mail: commit['Author']['Email']) - json.partial! 'repositories/commit_author', locals: { user: author, name: commit['Committer']['Name'] } + json.partial! 'repositories/commit_author', locals: { user: render_cache_commit_author(commit['Author']), name: commit['Author']['Name'] } end json.committer do - author = User.find_by(mail: commit['Committer']['Email']) - json.partial! 'repositories/commit_author', locals: { user: author, name: commit['Committer']['Name'] } + json.partial! 'repositories/commit_author', locals: { user: render_cache_commit_author(commit['Committer']), name: commit['Committer']['Name'] } end json.timestamp render_unix_time(commit['Committer']['When']) json.time_from_now time_from_now(commit['Committer']['When']) diff --git a/app/views/repositories/_commit.json.jbuilder b/app/views/repositories/_commit.json.jbuilder index 95cb03412..9c29116e9 100644 --- a/app/views/repositories/_commit.json.jbuilder +++ b/app/views/repositories/_commit.json.jbuilder @@ -26,9 +26,9 @@ if @project.forge? end json.author do - json.partial! 'commit_author', user: render_commit_author(commit['commit']['author']), name: commit['commit']['author']['name'] + json.partial! 'commit_author', user: render_cache_commit_author(commit['commit']['author']), name: commit['commit']['author']['name'] end json.committer do - json.partial! 'commit_author', user: render_commit_author(commit['commit']['committer']), name: commit['commit']['committer']['name'] + json.partial! 'commit_author', user: render_cache_commit_author(commit['commit']['committer']), name: commit['commit']['committer']['name'] end end diff --git a/app/views/repositories/_commit_author.json.jbuilder b/app/views/repositories/_commit_author.json.jbuilder index c63edf9b1..83935709a 100644 --- a/app/views/repositories/_commit_author.json.jbuilder +++ b/app/views/repositories/_commit_author.json.jbuilder @@ -1,9 +1,17 @@ -if user - json.id user.id - json.login user.login - json.name user.real_name - json.type user&.type - json.image_url url_to_avatar(user) +if user.present? + if user.is_a?(Hash) + json.id user["id"] + json.login user["login"] + json.name user["name"] + json.type user["type"] + json.image_url user["avatar_url"] + else + json.id user.id + json.login user.login + json.name user.real_name + json.type user&.type + json.image_url url_to_avatar(user) + end else json.id nil json.login name diff --git a/app/views/repositories/commits.json.jbuilder b/app/views/repositories/commits.json.jbuilder index cf4a409f5..33406e6a5 100644 --- a/app/views/repositories/commits.json.jbuilder +++ b/app/views/repositories/commits.json.jbuilder @@ -28,10 +28,10 @@ else # end # end json.author do - json.partial! 'commit_author', user: render_commit_author(commit['commit']['author']), name: commit['commit']['author']['name'] + json.partial! 'commit_author', user: render_cache_commit_author(commit['commit']['author']), name: commit['commit']['author']['name'] end json.committer do - json.partial! 'commit_author', user: render_commit_author(commit['commit']['committer']), name: commit['commit']['committer']['name'] + json.partial! 'commit_author', user: render_cache_commit_author(commit['commit']['committer']), name: commit['commit']['committer']['name'] end end end diff --git a/app/views/repositories/tags.json.jbuilder b/app/views/repositories/tags.json.jbuilder index d1ee3671e..eaf11058e 100644 --- a/app/views/repositories/tags.json.jbuilder +++ b/app/views/repositories/tags.json.jbuilder @@ -5,7 +5,7 @@ json.array! @tags do |tag| json.zipball_url render_zip_url(@owner, @repository, tag['name']) json.tarball_url render_tar_url(@owner, @repository, tag['name']) json.tagger do - json.partial! 'commit_author', user: render_commit_author(tag['tagger']), name: tag['tagger']['name'] + json.partial! 'commit_author', user: render_cache_commit_author(tag['tagger']), name: tag['tagger']['name'] end json.time_ago time_from_now(tag['tagger']['date'].to_time) json.created_at_unix tag['tagger']['date'].to_time.to_i @@ -16,10 +16,10 @@ json.array! @tags do |tag| json.time_ago time_from_now(tag['commit']['commiter']['date'].to_time) json.created_at_unix tag['commit']['commiter']['date'].to_time.to_i json.committer do - json.partial! 'commit_author', user: render_commit_author(tag['commit']['commiter']), name: tag['commit']['commiter']['name'] + json.partial! 'commit_author', user: render_cache_commit_author(tag['commit']['commiter']), name: tag['commit']['commiter']['name'] end json.author do - json.partial! 'commit_author', user: render_commit_author(tag['commit']['author']), name: tag['commit']['author']['name'] + json.partial! 'commit_author', user: render_cache_commit_author(tag['commit']['author']), name: tag['commit']['author']['name'] end end end