038 (issue rebuild) migration performance improvement #806
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
platform: # supported: 2.2.4, 2.3.2
backlogs: # supported: 1.0.5
ruby: # supported: 1.9.3, 2.0.0
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.