This commit is contained in:
yystopf 2023-02-24 14:32:21 +08:00
parent 35bb8fbc11
commit b616c971db
8 changed files with 25 additions and 8 deletions

View File

@ -4,8 +4,8 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController
before_action :require_operate_above, only: [:create, :update, :destroy]
def index
@issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
@issue_tags = @project.issue_tags.reorder("#{sort_by} #{sort_direction}")
@issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
if params[:only_name]
@issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color))
else

View File

@ -73,8 +73,8 @@ class Issue < ApplicationRecord
has_many :issue_participants, dependent: :destroy
has_many :participants, through: :issue_participants
has_many :show_participants, -> {joins(:issue_participants).where.not(issue_participants: {participant_type: "atme"}).distinct}, through: :issue_participants, source: :participant
has_many :show_assigners, -> {joins(:issue_assigners).order("issue_assigners.created_at desc").distinct.limit(5)}, through: :issue_assigners, source: :assigner
has_many :show_issue_tags, -> {joins(:issue_tags_relates).order("issue_tags_relates.created_at desc").distinct.limit(3)}, through: :issue_tags_relates, source: :issue_tag
has_many :show_assigners, -> {joins(:issue_assigners).distinct}, through: :issue_assigners, source: :assigner
has_many :show_issue_tags, -> {joins(:issue_tags_relates).distinct}, through: :issue_tags_relates, source: :issue_tag
has_many :comment_journals, -> {where.not(notes: nil)}, class_name: "Journal", :as => :journalized
has_many :operate_journals, -> {where(notes: nil)}, class_name: "Journal", :as => :journalized

View File

@ -48,5 +48,9 @@ class IssueTag < ApplicationRecord
$redis_cache.hset("project_init_issue_tags", project_id, 1)
end
def reset_counter_field
self.update_column(:issues_count, issue_issues.size)
self.update_column(:pull_requests_count, pull_request_issues.size)
end
end

View File

@ -18,12 +18,26 @@ class IssueTagsRelate < ApplicationRecord
belongs_to :issue_tag
after_create :increment_issue_tags_counter_cache
after_destroy :decrement_issue_tags_counter_cache
def increment_issue_tags_counter_cache
Rails.logger.info "11111"
Rails.logger.info self.issue.issue_classify
if self.issue.issue_classify == "issue"
IssueTag.increment_counter :issues_count, issue_tag_id
else
IssueTag.increment_counter :pull_requests_count, issue_tag_id
end
end
def decrement_issue_tags_counter_cache
Rails.logger.info "2222222"
Rails.logger.info self.issue.issue_classify
if self.issue.issue_classify == "issue"
IssueTag.decrement_counter :issues_count, issue_tag_id
else
IssueTag.decrement_counter :pull_requests_count, issue_tag_id
end
end
end

View File

@ -81,7 +81,7 @@ class Api::V1::Issues::ListService < ApplicationService
issues = issues.opened
end
scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :issue_tags, :comment_journals)
scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals)
scope = scope.reorder("#{sort_by} #{sort_direction}").distinct

View File

@ -57,7 +57,7 @@ class Api::V1::Issues::UpdateService < ApplicationService
build_atme_participants if @atme_receivers.present?
@updated_issue.assigners = @assigners || User.none unless assigner_ids.nil?
@updated_issue.attachments = @attachments || Attachment.none unless attachment_ids.nil?
@updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil?
@updated_issue.issue_tags_relates.destroy_all & @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil?
@updated_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil?
@updated_issue.updated_on = Time.now

View File

@ -1,7 +1,7 @@
json.(issue, :id, :subject, :project_issues_index, :description, :branch_name, :start_date, :due_date)
json.created_at issue.created_on.strftime("%Y-%m-%d %H:%M")
json.updated_at issue.updated_on.strftime("%Y-%m-%d %H:%M")
json.tags issue.issue_tags.each do |tag|
json.tags issue.show_issue_tags.each do |tag|
json.partial! "api/v1/issues/issue_tags/simple_detail", locals: {tag: tag}
end
json.status do

View File

@ -30,8 +30,7 @@ namespace :upgrade_issue_generate_data do
IssuePriority.init_data
IssueStatus.init_data
IssueTag.order(created_at: :desc).find_each do |it|
it.update_column(:issues_count, it.issue_issues.size)
it.update_column(:pull_requests_count, it.pull_request_issues.size)
it.reset_counter_field
end
IssueTag.where(user_id: nil).destroy_all
count = 0