Browse Source

add: repo commit user use cache data

tags/v4.0.0
yystopf 4 years ago
parent
commit
28c3b4dda4
9 changed files with 39 additions and 21 deletions
  1. +8
    -0
      app/helpers/application_helper.rb
  2. +4
    -0
      app/helpers/repositories_helper.rb
  3. +2
    -2
      app/views/projects/branches.json.jbuilder
  4. +2
    -2
      app/views/projects/branches_slice.json.jbuilder
  5. +2
    -4
      app/views/pull_requests/_commit.json.jbuilder
  6. +2
    -2
      app/views/repositories/_commit.json.jbuilder
  7. +14
    -6
      app/views/repositories/_commit_author.json.jbuilder
  8. +2
    -2
      app/views/repositories/commits.json.jbuilder
  9. +3
    -3
      app/views/repositories/tags.json.jbuilder

+ 8
- 0
app/helpers/application_helper.rb View File

@@ -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


+ 4
- 0
app/helpers/repositories_helper.rb View File

@@ -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


+ 2
- 2
app/views/projects/branches.json.jbuilder View File

@@ -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

+ 2
- 2
app/views/projects/branches_slice.json.jbuilder View File

@@ -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

+ 2
- 4
app/views/pull_requests/_commit.json.jbuilder View File

@@ -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'])


+ 2
- 2
app/views/repositories/_commit.json.jbuilder View File

@@ -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

+ 14
- 6
app/views/repositories/_commit_author.json.jbuilder View File

@@ -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


+ 2
- 2
app/views/repositories/commits.json.jbuilder View File

@@ -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


+ 3
- 3
app/views/repositories/tags.json.jbuilder View File

@@ -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


Loading…
Cancel
Save