diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index f0578d10e..78942fda9 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -196,7 +196,7 @@ class IssuesController < ApplicationController if params[:status_id].to_i == 5 @issue.issue_times.update_all(end_time: Time.now) - @issue.update_closed_issues_count_in_project! + # @issue.update_closed_issues_count_in_project! #已经有after_update方法了,这里就不需要了 end @issue.create_journal_detail(change_files, issue_files, issue_file_ids, current_user&.id) diff --git a/db/migrate/20200927023922_reset_versions_count.rb b/db/migrate/20200927023922_reset_versions_count.rb new file mode 100644 index 000000000..2c121e62d --- /dev/null +++ b/db/migrate/20200927023922_reset_versions_count.rb @@ -0,0 +1,17 @@ +class ResetVersionsCount < ActiveRecord::Migration[5.2] + def change + execute "ALTER TABLE licenses MODIFY COLUMN id INT AUTO_INCREMENT;" + versions = Version.includes(:issues).select(:id, :closed_issues_count, :percent,:issues_count) + versions.each do |v| + Version.reset_counters v.id, :issues + closed_issues = Issue.select(:id, :fixed_version_id, :status_id).where(fixed_version_id: v.id, status_id: 5).size + unless v.closed_issues_count.to_i == closed_issues + percent = v.issues_count.to_i <=0 ? 0.0 : (closed_issues.to_f / v.issues_count.to_i) + v.closed_issues_count = closed_issues + v.percent = percent + v.save + end + puts v.id + end + end +end