Merge pull request 'FIX 优化接口数据' (#211) from featrue_api_performance into develop
This commit is contained in:
commit
cd9a454a80
|
@ -0,0 +1,37 @@
|
||||||
|
|
||||||
|
module Gitea
|
||||||
|
module Repository
|
||||||
|
class GetBranchAndTagTotalNumService < Gitea::ClientService
|
||||||
|
attr_reader :owner, :repo, :token
|
||||||
|
|
||||||
|
def initialize(owner, repo, token=nil)
|
||||||
|
@owner = owner
|
||||||
|
@repo = repo
|
||||||
|
@token = token
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
response = get(url, params)
|
||||||
|
render_result(response)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def params
|
||||||
|
Hash.new.merge(token: token)
|
||||||
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
"/repos/#{owner}/#{repo}/branch_tag_count".freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_result(response)
|
||||||
|
case response.status
|
||||||
|
when 200
|
||||||
|
JSON.parse(response.body)
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,11 +10,9 @@ class Repositories::DetailService < ApplicationService
|
||||||
def call
|
def call
|
||||||
return {
|
return {
|
||||||
repo: repo_suitable,
|
repo: repo_suitable,
|
||||||
release: release_suitable,
|
|
||||||
branch: branch_suitable,
|
|
||||||
tag: tag_suitable,
|
|
||||||
contributor: contributor_suitable,
|
contributor: contributor_suitable,
|
||||||
language: language_suitable
|
language: language_suitable,
|
||||||
|
branch_tag_total_count: branch_tag_total_count
|
||||||
}
|
}
|
||||||
rescue
|
rescue
|
||||||
return {
|
return {
|
||||||
|
@ -30,25 +28,14 @@ class Repositories::DetailService < ApplicationService
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def branch_tag_total_count
|
||||||
|
Gitea::Repository::GetBranchAndTagTotalNumService.call(@owner.login, @repo.identifier, @owner.gitea_token)
|
||||||
|
end
|
||||||
|
|
||||||
def repo_suitable
|
def repo_suitable
|
||||||
Gitea::Repository::GetService.call(@owner, @repo.identifier)
|
Gitea::Repository::GetService.call(@owner, @repo.identifier)
|
||||||
end
|
end
|
||||||
|
|
||||||
def release_suitable
|
|
||||||
releases = Gitea::Versions::ListService.call(@owner.gitea_token, @owner.try(:login), @repo.try(:identifier), {page: 1, limit: 1})
|
|
||||||
releases.is_a?(Hash) && releases[:status] == -1 ? [] : releases
|
|
||||||
end
|
|
||||||
|
|
||||||
def branch_suitable
|
|
||||||
branches = Gitea::Repository::Branches::ListService.call(@owner, @repo.identifier)
|
|
||||||
branches.is_a?(Hash) && branches.key?(:status) ? [] : branches
|
|
||||||
end
|
|
||||||
|
|
||||||
def tag_suitable
|
|
||||||
tags = Gitea::Repository::Tags::ListService.call(@owner&.gitea_token, @owner.login, @repo.identifier)
|
|
||||||
tags.is_a?(Hash) && tags[:status] == -1 ? [] : tags
|
|
||||||
end
|
|
||||||
|
|
||||||
def contributor_suitable
|
def contributor_suitable
|
||||||
contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repo.identifier)
|
contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repo.identifier)
|
||||||
contributors.is_a?(Hash) && contributors.key?(:status) ? [] : contributors
|
contributors.is_a?(Hash) && contributors.key?(:status) ? [] : contributors
|
||||||
|
|
|
@ -51,28 +51,8 @@ if @result[:repo]
|
||||||
json.private @result[:repo]['private']
|
json.private @result[:repo]['private']
|
||||||
end
|
end
|
||||||
json.license_name @project.license_name
|
json.license_name @project.license_name
|
||||||
json.release_versions do
|
json.branches_count @result[:branch_tag_total_count]['branch_count'] || 0
|
||||||
json.list @result[:release].each do |release|
|
json.tags_count @result[:branch_tag_total_count]['tag_count'] || 0
|
||||||
forge_version = VersionRelease.find_by(version_gid: release["id"])
|
|
||||||
json.id forge_version&.id
|
|
||||||
json.name release["name"]
|
|
||||||
json.tag_name release["tag_name"]
|
|
||||||
json.created_at format_time(release["created_at"].to_time)
|
|
||||||
end
|
|
||||||
json.total_count @repository&.version_releases.size
|
|
||||||
end
|
|
||||||
json.branches do
|
|
||||||
json.list @result[:branch].each do |branch|
|
|
||||||
json.name branch["name"]
|
|
||||||
end
|
|
||||||
json.total_count @result[:branch].size
|
|
||||||
end
|
|
||||||
json.tags do
|
|
||||||
json.list @result[:tag].each do |tag|
|
|
||||||
json.name tag["name"]
|
|
||||||
end
|
|
||||||
json.total_count @result[:tag].size
|
|
||||||
end
|
|
||||||
json.contributors do
|
json.contributors do
|
||||||
total_count = @result[:contributor].size
|
total_count = @result[:contributor].size
|
||||||
json.list @result[:contributor].each do |contributor|
|
json.list @result[:contributor].each do |contributor|
|
||||||
|
|
Loading…
Reference in New Issue