迁移优化,原来需要1800秒,现只需800秒

This commit is contained in:
guange 2015-03-09 16:25:41 +08:00
parent 0402fee6de
commit c893a2d99b
1 changed files with 6 additions and 4 deletions

View File

@ -1,9 +1,11 @@
class AddDataToProjectIssuesIndexsInIssue < ActiveRecord::Migration
def change
for i in 1 ... 1000 do i
Issue.page(i).per(10).each do |e|
index = e.project.issues.index(e).to_i + 1
execute("update issues set project_issues_index = #{index} where id = #{e.id}")
transaction do
for i in 1 ... 1000 do i
Issue.page(i).per(10).each do |e|
index = e.project.issues.index(e).to_i + 1
execute("update issues set project_issues_index = #{index} where id = #{e.id}")
end
end
end
end