forked from Gitlink/forgeplus
项目的列表页修改数量参数
This commit is contained in:
parent
e3d0904e2c
commit
8aed492dae
|
@ -2,6 +2,6 @@ class IssueTag < ApplicationRecord
|
|||
|
||||
has_many :issue_tags_relates, dependent: :destroy
|
||||
has_many :issues, through: :issue_tags_relates
|
||||
belongs_to :project, optional: true
|
||||
belongs_to :project, optional: true, counter_cache: true
|
||||
|
||||
end
|
||||
|
|
|
@ -120,4 +120,16 @@ class Project < ApplicationRecord
|
|||
is_public? || User.current.admin? || member?(User.current)
|
||||
end
|
||||
|
||||
def version_releases_size(current_user_id, type)
|
||||
if current_user_id == self.user_id && type.to_s == "all"
|
||||
self.repository.version_releases_count
|
||||
else
|
||||
self.repository.version_releases.releases_size
|
||||
end
|
||||
end
|
||||
|
||||
def contributor_users
|
||||
self.pull_requests.select(:user_id).pluck(:user_id).uniq.size
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Version < ApplicationRecord
|
||||
belongs_to :project
|
||||
belongs_to :project, counter_cache: true
|
||||
has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id"
|
||||
belongs_to :user, optional: true
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class VersionRelease < ApplicationRecord
|
||||
belongs_to :repository
|
||||
belongs_to :repository, counter_cache: true
|
||||
belongs_to :user
|
||||
has_many :project_trends, as: :trend, dependent: :destroy
|
||||
scope :releases_size, ->{where(draft: false, prerelease: false)}
|
||||
# has_many :attachments, as: :container, dependent: :destroy
|
||||
end
|
||||
|
|
|
@ -7,6 +7,11 @@ json.project_identifier @project.identifier
|
|||
json.praises_count @project.praises_count.to_i
|
||||
json.forked_count @project.forked_count.to_i
|
||||
json.watchers_count @project.watchers_count.to_i
|
||||
json.versions_count @project.versions_count #里程碑数量
|
||||
json.version_releases_count @project.releases_size(current_user.try(:id), "all")
|
||||
json.version_releasesed_count @project.releases_size(current_user.try(:id), "released") #已发行的版本
|
||||
json.contributor_users_count @project.contributor_users
|
||||
json.issue_tags_count @project.issue_tags_count
|
||||
json.branches_count @branches_count
|
||||
json.commits_count @commits_count
|
||||
json.permission render_edit_project_permission(current_user, @project) if current_user
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
class AddSomeCountsToProject < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :projects, :versions_count, :integer, default: 0 #里程碑
|
||||
add_column :repositories, :version_releases_count, :integer, default: 0 #版本发布d
|
||||
add_column :projects, :issue_tags_count, :integer, default: 0 #标签的数量
|
||||
|
||||
Project.includes(:versions, :issue_tags, repository: :version_releases).find_each do |p|
|
||||
puts "###____change_p.id____######{p.id}"
|
||||
r = p&.repository
|
||||
Project.reset_counters p.id, :versions
|
||||
Project.reset_counters p.id, :issue_tags
|
||||
|
||||
if r.present?
|
||||
puts "###____change_p.id____######{r.id}"
|
||||
Repository.reset_counters r.id, :version_releases
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue