github/gitscm-next — pull request #109 by bry4n (2012-05-13 03:32:26+00:00)
Title: N+1 Query fix for DocVersion.version_changes

Just improved the SQL query because the `DocVersion.version_changes(git_command)` generated a lot of `SELECT "versions".* FROM "versions" WHERE "versions"."id" = ? LIMIT 1`

```
DocVersion Load (109.4ms) SELECT "doc_versions".* FROM "doc_versions" INNER JOIN "doc_files" ON "doc_files"."id" = "doc_versions"."doc_file_id" INNER JOIN "versions" ON "versions"."id" = "doc_versions"."version_id" WHERE (doc_files.name='git-blame') ORDER BY versions.vorder DESC
Doc Load (1.0ms) SELECT "docs".* FROM "docs" WHERE "docs"."id" IN (2309, 2925, 2769, 2678, 2261, 2230, 2083, 2057, 1817, 1787, 1744, 1729, 1645, 1416, 1356, 1198, 1074, 943, 764, 713, 662, 652, 478, 441, 396, 345, 289, 191)
Version Load (0.2ms) SELECT "versions".* FROM "versions" WHERE "versions"."id" = 165 LIMIT 1
Version Load (0.2ms) SELECT "versions".* FROM "versions" WHERE "versions"."id" = 164 LIMIT 1
Version Load (0.1ms) SELECT "versions".* FROM "versions" WHERE "versions"."id" = 163 LIMIT 1
Version Load (0.1ms) SELECT "versions".* FROM "versions" WHERE "versions"."id" = 213 LIMIT 1
Version Load (0.1ms) SELECT "versions".* FROM "versions" WHERE "versions"."id" = 212 LIMIT 1
Version Load (0.1ms) SELECT "versions".* FROM "versions" WHERE "versions"."id" = 211 LIMIT 1
Version Load (0.1ms) SELECT "versions".* FROM "versions" WHERE "versions"."id" = 210 LIMIT 1
Version Load (0.1ms) SELECT "versions".* FROM "versions" WHERE "versions"."id" = 209 LIMIT 1
Version Load (0.1ms) SELECT "versions".* FROM "versions" WHERE "versions"."id" = 208 LIMIT 1
*** CUT ***
=> [{:name=>"1.7.8.1 → 1.7.10.2 no changes", :changed=>false}, {:name=>"1.7.8", :time=>Fri, 02 Dec 2011 18:02:52 UTC +00:00, :diff=>[1, 0, 7], :changed=>true}, {:name=>"1.7.6.1 → 1.7.7.7 no changes", :changed=>false}, {:name=>"1.7.6", :time=>Sun, 26 Jun 2011 19:41:16 UTC +00:00, :diff=>[1, 1, 6], :changed=>true}, {:name=>"1.7.5.1 → 1.7.5.4 no changes", :changed=>false}, {:name=>"1.7.5", :time=>Sun, 24 Apr 2011 06:36:32 UTC +00:00, :diff=>[4, 0, 4], :changed=>true}, {:name=>"1.7.4.1 → 1.7.4.5 no changes", :changed=>false}, {:name=>"1.7.4", :time=>Mon, 31 Jan 2011 03:02:37 UTC +00:00, :diff=>[1, 1, 6], :changed=>true}, {:name=>"1.7.1.2 → 1.7.3.5 no changes", :changed=>false}, {:name=>"1.7.1.1", :time=>Tue, 29 Jun 2010 16:59:56 UTC +00:00, :diff=>[1, 1, 6], :changed=>true}, {:name=>"1.7.0.6 → 1.7.1 no changes", :changed=>false}, {:name=>"1.7.0.5", :time=>Sun, 11 Apr 2010 20:42:33 UTC +00:00, :diff=>[3, 4, -9], :changed=>true}, {:name=>"1.7.0.1 → 1.7.0.4 no changes", :changed=>false}, {:name=>"1.7.0", :time=>Fri, 12 Feb 2010 23:45:05 UTC +00:00, :diff=>[1, 1, 6], :changed=>true}, {:name=>"1.6.6.2 → 1.6.6.3 no changes", :changed=>false}, {:name=>"1.6.6.1", :time=>Wed, 20 Jan 2010 21:29:21 UTC +00:00, :diff=>[1, 1, 6], :changed=>true}, {:name=>"1.6.3.1 → 1.6.6 no changes", :changed=>false}, {:name=>"1.6.3", :time=>Thu, 07 May 2009 01:16:40 UTC +00:00, :diff=>[0, 8, 0], :changed=>true}, {:name=>"1.6.2.3 → 1.6.2.5 no changes", :changed=>false}, {:name=>"1.6.2.2", :time=>Thu, 02 Apr 2009 19:34:16 UTC +00:00, :diff=>[1, 1, 6], :changed=>true}]
```
---

The fix has addressed the n+1 query problem.