{"action":"created","issue":{"url":"https://api.github.com/repos/flyerhzm/bullet/issues/208","labels_url":"https://api.github.com/repos/flyerhzm/bullet/issues/208/labels{/name}","comments_url":"https://api.github.com/repos/flyerhzm/bullet/issues/208/comments","events_url":"https://api.github.com/repos/flyerhzm/bullet/issues/208/events","html_url":"https://github.com/flyerhzm/bullet/issues/208","id":54965073,"number":208,"title":"False Positives with Goldiloads gem","user":{"login":"BenMorganIO","id":3117356,"avatar_url":"https://avatars.githubusercontent.com/u/3117356?v=3","gravatar_id":"","url":"https://api.github.com/users/BenMorganIO","html_url":"https://github.com/BenMorganIO","followers_url":"https://api.github.com/users/BenMorganIO/followers","following_url":"https://api.github.com/users/BenMorganIO/following{/other_user}","gists_url":"https://api.github.com/users/BenMorganIO/gists{/gist_id}","starred_url":"https://api.github.com/users/BenMorganIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BenMorganIO/subscriptions","organizations_url":"https://api.github.com/users/BenMorganIO/orgs","repos_url":"https://api.github.com/users/BenMorganIO/repos","events_url":"https://api.github.com/users/BenMorganIO/events{/privacy}","received_events_url":"https://api.github.com/users/BenMorganIO/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-21T01:20:49Z","updated_at":"2015-02-05T11:10:11Z","closed_at":null,"body":"The Goldiloads gem is used to automatically fix those n+1s. In a large rails application with at least 100 models, it saves you from a large amount of manual work.\r\n\r\nWhen using the Goldiloads gem, any n+1s that it fixes are still reaching Bullets log.\r\n\r\nUsing a standard Spree application with Goldiloads:\r\n\r\n```sql\r\n16:54:20 web.1    | Started GET \"/cart\" for 127.0.0.1 at 2015-01-20 16:54:20 -0800\r\n16:54:22 web.1    | Processing by OrdersController#edit as HTML\r\n16:54:22 web.1    |   Spree::User Load (0.6ms)  SELECT  \"spree_users\".* FROM \"spree_users\"  WHERE \"spree_users\".\"deleted_at\" IS NULL AND \"spree_users\".\"id\" = 1  ORDER BY \"spree_users\".\"id\" ASC LIMIT 1\r\n16:54:22 web.1    |   Spree::Store Load (0.6ms)  SELECT  \"spree_stores\".* FROM \"spree_stores\"  WHERE (url like '%localhost%')  ORDER BY \"spree_stores\".\"id\" ASC LIMIT 1\r\n16:54:22 web.1    |   Spree::Store Load (0.4ms)  SELECT  \"spree_stores\".* FROM \"spree_stores\"  WHERE \"spree_stores\".\"default\" = 't'  ORDER BY \"spree_stores\".\"id\" ASC LIMIT 1\r\n16:54:22 web.1    |   Spree::Order Load (1.0ms)  SELECT  \"spree_orders\".* FROM \"spree_orders\"  WHERE \"spree_orders\".\"completed_at\" IS NULL AND \"spree_orders\".\"currency\" = 'USD' AND \"spree_orders\".\"guest_token\" = 'tziKmOATnEJ1lBnOYcI2TA' AND \"spree_orders\".\"store_id\" = 1 AND \"spree_orders\".\"user_id\" = 1 LIMIT 1\r\n16:54:22 web.1    |   Spree::Order Load (0.8ms)  SELECT  \"spree_orders\".* FROM \"spree_orders\"  WHERE \"spree_orders\".\"user_id\" = $1 AND \"spree_orders\".\"completed_at\" IS NULL AND \"spree_orders\".\"user_id\" = 1  ORDER BY created_at DESC LIMIT 1  [[\"user_id\", 1]]\r\n16:54:22 web.1    |   Spree::Order Load (1.0ms)  SELECT \"spree_orders\".* FROM \"spree_orders\"  WHERE \"spree_orders\".\"user_id\" = $1 AND \"spree_orders\".\"completed_at\" IS NULL AND (id != 54)  [[\"user_id\", 1]]\r\n16:54:22 web.1    |   Spree::Order Load (0.8ms)  SELECT  \"spree_orders\".* FROM \"spree_orders\"  WHERE \"spree_orders\".\"id\" = $1 LIMIT 1  [[\"id\", 54]]\r\n16:54:22 web.1    |   Spree::User Load (0.7ms)  SELECT \"spree_users\".* FROM \"spree_users\"  WHERE \"spree_users\".\"deleted_at\" IS NULL AND \"spree_users\".\"id\" IN (1)\r\n16:54:22 web.1    |   Spree::LineItem Exists (0.3ms)  SELECT  1 AS one FROM \"spree_line_items\"  WHERE \"spree_line_items\".\"order_id\" = $1 LIMIT 1  [[\"order_id\", 54]]\r\n16:54:22 web.1    |   Spree::LineItem Load (1.1ms)  SELECT \"spree_line_items\".* FROM \"spree_line_items\"  WHERE \"spree_line_items\".\"order_id\" IN (54)  ORDER BY spree_line_items.created_at ASC\r\n16:54:22 web.1    |   Spree::Variant Load (1.5ms)  SELECT \"spree_variants\".* FROM \"spree_variants\"  WHERE \"spree_variants\".\"deleted_at\" IS NULL AND \"spree_variants\".\"id\" IN (756, 758, 741, 771, 1179, 773, 770, 772, 767, 769, 774)\r\n16:54:22 web.1    |   Spree::Image Load (0.8ms)  SELECT \"spree_assets\".* FROM \"spree_assets\"  WHERE \"spree_assets\".\"type\" IN ('Spree::Image') AND \"spree_assets\".\"viewable_type\" = 'Spree::Variant' AND \"spree_assets\".\"viewable_id\" IN (770, 741, 758, 756, 769, 771, 772, 767, 773, 774, 1179)  ORDER BY \"spree_assets\".\"position\" ASC\r\n16:54:22 web.1    |   Spree::Product Load (0.6ms)  SELECT \"spree_products\".* FROM \"spree_products\"  WHERE \"spree_products\".\"deleted_at\" IS NULL AND \"spree_products\".\"id\" IN (24, 35)\r\n16:54:22 web.1    |   HABTM_OptionValues Load (0.5ms)  SELECT \"spree_option_values_variants\".* FROM \"spree_option_values_variants\"  WHERE \"spree_option_values_variants\".\"variant_id\" IN (770, 741, 758, 756, 769, 771, 772, 767, 773, 774, 1179)\r\n16:54:22 web.1    |   Spree::OptionValue Load (0.5ms)  SELECT \"spree_option_values\".* FROM \"spree_option_values\"  WHERE \"spree_option_values\".\"id\" IN (22, 33, 12, 30, 10, 32, 27, 31, 19, 23, 24, 25, 34)\r\n16:54:22 web.1    |   Spree::OptionType Load (0.8ms)  SELECT \"spree_option_types\".* FROM \"spree_option_types\"  WHERE \"spree_option_types\".\"id\" IN (2, 1)  ORDER BY spree_option_types.position\r\n16:54:22 web.1    |    (1.2ms)  SELECT SUM(\"spree_stock_items\".\"count_on_hand\") AS sum_id FROM \"spree_stock_items\" INNER JOIN \"spree_stock_locations\" ON \"spree_stock_locations\".\"id\" = \"spree_stock_items\".\"stock_location_id\" WHERE \"spree_stock_items\".\"deleted_at\" IS NULL AND \"spree_stock_items\".\"variant_id\" = 756 AND \"spree_stock_locations\".\"active\" = 't'\r\n16:54:22 web.1    |    (1.3ms)  SELECT SUM(\"spree_stock_items\".\"count_on_hand\") AS sum_id FROM \"spree_stock_items\" INNER JOIN \"spree_stock_locations\" ON \"spree_stock_locations\".\"id\" = \"spree_stock_items\".\"stock_location_id\" WHERE \"spree_stock_items\".\"deleted_at\" IS NULL AND \"spree_stock_items\".\"variant_id\" = 758 AND \"spree_stock_locations\".\"active\" = 't'\r\n16:54:22 web.1    |    (1.2ms)  SELECT SUM(\"spree_stock_items\".\"count_on_hand\") AS sum_id FROM \"spree_stock_items\" INNER JOIN \"spree_stock_locations\" ON \"spree_stock_locations\".\"id\" = \"spree_stock_items\".\"stock_location_id\" WHERE \"spree_stock_items\".\"deleted_at\" IS NULL AND \"spree_stock_items\".\"variant_id\" = 741 AND \"spree_stock_locations\".\"active\" = 't'\r\n16:54:22 web.1    |    (1.2ms)  SELECT SUM(\"spree_stock_items\".\"count_on_hand\") AS sum_id FROM \"spree_stock_items\" INNER JOIN \"spree_stock_locations\" ON \"spree_stock_locations\".\"id\" = \"spree_stock_items\".\"stock_location_id\" WHERE \"spree_stock_items\".\"deleted_at\" IS NULL AND \"spree_stock_items\".\"variant_id\" = 771 AND \"spree_stock_locations\".\"active\" = 't'\r\n16:54:22 web.1    |    (1.4ms)  SELECT SUM(\"spree_stock_items\".\"count_on_hand\") AS sum_id FROM \"spree_stock_items\" INNER JOIN \"spree_stock_locations\" ON \"spree_stock_locations\".\"id\" = \"spree_stock_items\".\"stock_location_id\" WHERE \"spree_stock_items\".\"deleted_at\" IS NULL AND \"spree_stock_items\".\"variant_id\" = 1179 AND \"spree_stock_locations\".\"active\" = 't'\r\n16:54:22 web.1    |    (1.4ms)  SELECT SUM(\"spree_stock_items\".\"count_on_hand\") AS sum_id FROM \"spree_stock_items\" INNER JOIN \"spree_stock_locations\" ON \"spree_stock_locations\".\"id\" = \"spree_stock_items\".\"stock_location_id\" WHERE \"spree_stock_items\".\"deleted_at\" IS NULL AND \"spree_stock_items\".\"variant_id\" = 773 AND \"spree_stock_locations\".\"active\" = 't'\r\n16:54:22 web.1    |    (1.5ms)  SELECT SUM(\"spree_stock_items\".\"count_on_hand\") AS sum_id FROM \"spree_stock_items\" INNER JOIN \"spree_stock_locations\" ON \"spree_stock_locations\".\"id\" = \"spree_stock_items\".\"stock_location_id\" WHERE \"spree_stock_items\".\"deleted_at\" IS NULL AND \"spree_stock_items\".\"variant_id\" = 770 AND \"spree_stock_locations\".\"active\" = 't'\r\n16:54:22 web.1    |    (1.2ms)  SELECT SUM(\"spree_stock_items\".\"count_on_hand\") AS sum_id FROM \"spree_stock_items\" INNER JOIN \"spree_stock_locations\" ON \"spree_stock_locations\".\"id\" = \"spree_stock_items\".\"stock_location_id\" WHERE \"spree_stock_items\".\"deleted_at\" IS NULL AND \"spree_stock_items\".\"variant_id\" = 772 AND \"spree_stock_locations\".\"active\" = 't'\r\n16:54:23 web.1    |    (1.6ms)  SELECT SUM(\"spree_stock_items\".\"count_on_hand\") AS sum_id FROM \"spree_stock_items\" INNER JOIN \"spree_stock_locations\" ON \"spree_stock_locations\".\"id\" = \"spree_stock_items\".\"stock_location_id\" WHERE \"spree_stock_items\".\"deleted_at\" IS NULL AND \"spree_stock_items\".\"variant_id\" = 767 AND \"spree_stock_locations\".\"active\" = 't'\r\n16:54:23 web.1    |    (1.2ms)  SELECT SUM(\"spree_stock_items\".\"count_on_hand\") AS sum_id FROM \"spree_stock_items\" INNER JOIN \"spree_stock_locations\" ON \"spree_stock_locations\".\"id\" = \"spree_stock_items\".\"stock_location_id\" WHERE \"spree_stock_items\".\"deleted_at\" IS NULL AND \"spree_stock_items\".\"variant_id\" = 769 AND \"spree_stock_locations\".\"active\" = 't'\r\n16:54:23 web.1    |    (1.5ms)  SELECT SUM(\"spree_stock_items\".\"count_on_hand\") AS sum_id FROM \"spree_stock_items\" INNER JOIN \"spree_stock_locations\" ON \"spree_stock_locations\".\"id\" = \"spree_stock_items\".\"stock_location_id\" WHERE \"spree_stock_items\".\"deleted_at\" IS NULL AND \"spree_stock_items\".\"variant_id\" = 774 AND \"spree_stock_locations\".\"active\" = 't'\r\n16:54:23 web.1    |   Rendered cart/_line_item.html.haml (809.5ms)\r\n16:54:23 web.1    |   Spree::Adjustment Exists (0.6ms)  SELECT  1 AS one FROM \"spree_adjustments\"  WHERE \"spree_adjustments\".\"adjustable_id\" = $1 AND \"spree_adjustments\".\"adjustable_type\" = $2 AND (\"spree_adjustments\".amount != 0) LIMIT 1  [[\"adjustable_id\", 54], [\"adjustable_type\", \"Spree::Order\"]]\r\n16:54:23 web.1    |   Spree::Adjustment Exists (1.1ms)  SELECT  1 AS one FROM \"spree_adjustments\" INNER JOIN \"spree_line_items\" ON \"spree_adjustments\".\"adjustable_id\" = \"spree_line_items\".\"id\" WHERE \"spree_adjustments\".\"adjustable_type\" = $1 AND \"spree_line_items\".\"order_id\" = $2 AND (\"spree_adjustments\".amount != 0) LIMIT 1  [[\"adjustable_type\", \"Spree::LineItem\"], [\"order_id\", 54]]\r\n16:54:23 web.1    |   Spree::Adjustment Exists (0.8ms)  SELECT  1 AS one FROM \"spree_adjustments\" INNER JOIN \"spree_shipments\" ON \"spree_adjustments\".\"adjustable_id\" = \"spree_shipments\".\"id\" WHERE \"spree_adjustments\".\"adjustable_type\" = $1 AND \"spree_shipments\".\"order_id\" = $2 AND (\"spree_adjustments\".amount != 0) LIMIT 1  [[\"adjustable_type\", \"Spree::Shipment\"], [\"order_id\", 54]]\r\n16:54:23 web.1    |   Spree::Shipment Exists (0.4ms)  SELECT  1 AS one FROM \"spree_shipments\"  WHERE \"spree_shipments\".\"order_id\" = $1 LIMIT 1  [[\"order_id\", 54]]\r\n16:54:23 web.1    |   Rendered cart/_form.html.haml (961.2ms)\r\n16:54:23 web.1    |   Rendered cart/edit.html.haml within layouts/application (1024.4ms)\r\n16:54:23 web.1    |   Rendered shared/_typekit.html.haml (0.2ms)\r\n16:54:23 web.1    |   Rendered shared/_meta_tags.html.haml (0.9ms)\r\n16:54:24 web.1    |   CACHE (0.1ms)  SELECT  \"spree_orders\".* FROM \"spree_orders\"  WHERE \"spree_orders\".\"completed_at\" IS NULL AND \"spree_orders\".\"currency\" = 'USD' AND \"spree_orders\".\"guest_token\" = 'tziKmOATnEJ1lBnOYcI2TA' AND \"spree_orders\".\"store_id\" = 1 AND \"spree_orders\".\"user_id\" = 1 LIMIT 1\r\n16:54:24 web.1    |   Rendered shared/_header.html.haml (12.6ms)\r\n16:54:24 web.1    |   Rendered shared/_flashes.html.haml (0.5ms)\r\n16:54:24 web.1    |   Rendered shared/_footer.html.haml (0.2ms)\r\n16:54:24 web.1    | Completed 200 OK in 2248ms (Views: 2077.9ms | ActiveRecord: 71.1ms)\r\n16:54:24 web.1    | user: benmorgan\r\n16:54:24 web.1    | /cart\r\n16:54:24 web.1    | N+1 Query detected\r\n16:54:24 web.1    |   Spree::Variant => [:images]\r\n16:54:24 web.1    |   Add to your finder: :include => [:images]\r\n16:54:24 web.1    | N+1 Query method call stack\r\n16:54:24 web.1    |   /Users/benmorgan/Sites/private/rails_app/app/views/cart/_line_item.html.haml:5:in `block in _e7dc8bb3bb3668103e24a61f0b5b0657'\r\n16:54:24 web.1    |   /Users/benmorgan/Sites/private/rails_app/app/views/cart/_line_item.html.haml:2:in `_e7dc8bb3bb3668103e24a61f0b5b0657'\r\n16:54:24 web.1    |   /Users/benmorgan/Sites/private/rails_app/app/views/cart/_form.html.haml:11:in `_f7d2639e377842577341525c7af08f3f'\r\n16:54:24 web.1    |   /Users/benmorgan/Sites/private/rails_app/app/views/cart/edit.html.haml:7:in `block in _f378ccf772b7c66d96389a09f5df26b0'\r\n16:54:24 web.1    |   /Users/benmorgan/Sites/private/rails_app/app/views/cart/edit.html.haml:6:in `_f378ccf772b7c66d96389a09f5df26b0'\r\n16:54:24 web.1    |\r\n16:54:24 web.1    | user: benmorgan\r\n16:54:24 web.1    | /cart\r\n16:54:24 web.1    | N+1 Query detected\r\n16:54:24 web.1    |   Spree::Variant => [:option_values]\r\n16:54:24 web.1    |   Add to your finder: :include => [:option_values]\r\n16:54:24 web.1    | N+1 Query method call stack\r\n16:54:24 web.1    |   /Users/benmorgan/Sites/private/rails_app/app/views/cart/_line_item.html.haml:11:in `block in _e7dc8bb3bb3668103e24a61f0b5b0657'\r\n16:54:24 web.1    |   /Users/benmorgan/Sites/private/rails_app/app/views/cart/_line_item.html.haml:2:in `_e7dc8bb3bb3668103e24a61f0b5b0657'\r\n16:54:24 web.1    |   /Users/benmorgan/Sites/private/rails_app/app/views/cart/_form.html.haml:11:in `_f7d2639e377842577341525c7af08f3f'\r\n16:54:24 web.1    |   /Users/benmorgan/Sites/private/rails_app/app/views/cart/edit.html.haml:7:in `block in _f378ccf772b7c66d96389a09f5df26b0'\r\n16:54:24 web.1    |   /Users/benmorgan/Sites/private/rails_app/app/views/cart/edit.html.haml:6:in `_f378ccf772b7c66d96389a09f5df26b0'\r\n```\r\n\r\nNotice that the option values and the images are already loaded."},"comment":{"url":"https://api.github.com/repos/flyerhzm/bullet/issues/comments/73029981","html_url":"https://github.com/flyerhzm/bullet/issues/208#issuecomment-73029981","issue_url":"https://api.github.com/repos/flyerhzm/bullet/issues/208","id":73029981,"user":{"login":"flyerhzm","id":66836,"avatar_url":"https://avatars.githubusercontent.com/u/66836?v=3","gravatar_id":"","url":"https://api.github.com/users/flyerhzm","html_url":"https://github.com/flyerhzm","followers_url":"https://api.github.com/users/flyerhzm/followers","following_url":"https://api.github.com/users/flyerhzm/following{/other_user}","gists_url":"https://api.github.com/users/flyerhzm/gists{/gist_id}","starred_url":"https://api.github.com/users/flyerhzm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flyerhzm/subscriptions","organizations_url":"https://api.github.com/users/flyerhzm/orgs","repos_url":"https://api.github.com/users/flyerhzm/repos","events_url":"https://api.github.com/users/flyerhzm/events{/privacy}","received_events_url":"https://api.github.com/users/flyerhzm/received_events","type":"User","site_admin":false},"created_at":"2015-02-05T11:10:10Z","updated_at":"2015-02-05T11:10:10Z","body":"@BenMorganIO could you try the latest bullet? "}}