backlogs/redmine_backlogs — pull request #806 by rpuch (2013-01-22 21:02:54+00:00)
Title: 038 (issue rebuild) migration performance improvement

038 migration is pretty slow because in it a lot of work is made in individual INSERT/UPDATE queries. However, this migration seems to actually just add data to rb_sprint_burndown and rb_issue_history, so it's much faster to insert them in a bulk and don't do UPDATEs at all.

This is the main idea of the fix. To implement it, I had to evade calling issue.history everywhere because it momentarily makes an INSERT. Also, all calculations are made first (in memory), and only then data is inserted.

Besides this, some redundant SELECT and SHOW TABLES queries were removed.
It still can be improved, however (still too much queries), but it takes now 860 seconds on my DB versus more than 9000 seconds for initial implementation in v0.9.32 tag.

This approach has a possible downside: as associations are maintained manually, if Ruby code changes in the future, it can break this migration logic.