code-dot-org/dashboard — pull request #891 by wjordan (2014-06-26 01:37:12+00:00)
Title: Optimize script update

Several optimizations to reduce the number of ActiveRecord calls (and corresponding SQL queries) during updates to a script. Focused on optimizing the basic reloading process where nothing (or very little) has changed in a very large script. High level:
1. acts_as_list has a really slow update mechanism. When possible, don't reset the positions of all acts_as_list members on each reload, and assign explicit `position` integers rather than `move_to_bottom`.
2. Instead of doing separate find_or_create for each item, load all associated items through an include directive on the Script, which will eliminate extra queries on existing items.
3. Explicitly cache effectively static models (Game, Concept).
4. Help Activerecord eliminate some extra queries by calling `#assign_attributes` and `#save if changed?` instead of `#update`.