更改:child_count使用count_cache

This commit is contained in:
yystopf 2023-11-23 08:53:02 +08:00
parent f8a6dcb3eb
commit 1a067d0607
1 changed files with 3 additions and 1 deletions

View File

@ -67,6 +67,7 @@ class Issue < ApplicationRecord
belongs_to :version, foreign_key: :fixed_version_id,optional: true, counter_cache: true
belongs_to :user,optional: true, foreign_key: :author_id
belongs_to :issue_status, foreign_key: :status_id,optional: true
belongs_to :parent_issue, class_name: 'Issue', optional: true, foreign_key: :root_id, counter_cache: :child_count
has_many :commit_issues
has_many :attachments, as: :container, dependent: :destroy
# has_many :memos
@ -103,7 +104,7 @@ class Issue < ApplicationRecord
scope :closed, ->{where(status_id: 5)}
scope :opened, ->{where.not(status_id: 5)}
after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic
after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :refresh_root_issue_count, :generate_uuid
after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :generate_uuid
after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic
def incre_project_common
@ -128,6 +129,7 @@ class Issue < ApplicationRecord
root_count = Issue.where(root_id: root_id).count
root_issue.update(child_count: root_count)
end
def incre_platform_statistic
CacheAsyncSetJob.perform_later('platform_statistic_service', {issue_count: 1})
end