{"action":"created","issue":{"url":"https://api.github.com/repos/Growstuff/growstuff/issues/841","repository_url":"https://api.github.com/repos/Growstuff/growstuff","labels_url":"https://api.github.com/repos/Growstuff/growstuff/issues/841/labels{/name}","comments_url":"https://api.github.com/repos/Growstuff/growstuff/issues/841/comments","events_url":"https://api.github.com/repos/Growstuff/growstuff/issues/841/events","html_url":"https://github.com/Growstuff/growstuff/pull/841","id":143967487,"number":841,"title":"Eager load photos to reduce the number of queries executed","user":{"login":"CloCkWeRX","id":365751,"avatar_url":"https://avatars.githubusercontent.com/u/365751?v=3","gravatar_id":"","url":"https://api.github.com/users/CloCkWeRX","html_url":"https://github.com/CloCkWeRX","followers_url":"https://api.github.com/users/CloCkWeRX/followers","following_url":"https://api.github.com/users/CloCkWeRX/following{/other_user}","gists_url":"https://api.github.com/users/CloCkWeRX/gists{/gist_id}","starred_url":"https://api.github.com/users/CloCkWeRX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CloCkWeRX/subscriptions","organizations_url":"https://api.github.com/users/CloCkWeRX/orgs","repos_url":"https://api.github.com/users/CloCkWeRX/repos","events_url":"https://api.github.com/users/CloCkWeRX/events{/privacy}","received_events_url":"https://api.github.com/users/CloCkWeRX/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-28T12:41:19Z","updated_at":"2016-03-28T12:50:52Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Growstuff/growstuff/pulls/841","html_url":"https://github.com/Growstuff/growstuff/pull/841","diff_url":"https://github.com/Growstuff/growstuff/pull/841.diff","patch_url":"https://github.com/Growstuff/growstuff/pull/841.patch"},"body":"Fixes #840 \r\n\r\nBefore: Large number of queries\r\n\r\nAfter - it's down to two (though we should probably add sane limits or find_in_batches so we don't have to grab *every* crop; and rely on some other random() behaviour)\r\n```\r\n  Crop Load (2.4ms)  SELECT \"crops\".* FROM \"crops\"  WHERE \"crops\".\"approval_status\" = 'approved'  ORDER BY random()\r\n  Planting Load (1.0ms)  SELECT \"plantings\".* FROM \"plantings\"  WHERE \"plantings\".\"crop_id\" IN (239, 390, 80, 8, 292, 199, 227, 18, 78, 230, 307, 191, 13, 348, 340, 74, 366, 313, 54, 206, 172, 24, 335, 202, 61, 181, 178, 397, 70, 217, 208, 118, 399, 341, 251, 41, 140, 275, 319, 46, 233, 147, 193, 7, 49, 108, 370, 126, 111, 338, 243, 398, 265, 209, 127, 232, 273, 364, 48, 259, 186, 271, 221, 197, 138, 290, 150, 81, 231, 311, 342, 42, 215, 14, 212, 252, 169, 310, 143, 210, 278, 358, 407, 166, 344, 59, 45, 356, 408, 68, 151, 314, 177, 115, 176, 254, 107, 60, 323, 277, 189, 168, 333, 224, 16, 27, 106, 385, 291, 173, 30, 298, 109, 32, 85, 201, 12, 134, 245, 11, 374, 425, 402, 419, 246, 403, 434, 297, 303, 362, 293, 393, 360, 22, 159, 220, 430, 179, 388, 302, 50, 185, 83, 418, 36, 4, 326, 322, 198, 267, 67, 200, 369, 282, 325, 400, 320, 249, 422, 44, 339, 190, 384, 276, 96, 66, 355, 414, 383, 117, 315, 367, 21, 156, 304, 77, 261, 300, 429, 380, 23, 296, 160, 148, 122, 95, 39, 141, 289, 427, 114, 112, 103, 409, 145, 350, 372, 396, 65, 170, 175, 9, 387, 29, 31, 305, 132, 182, 257, 281, 248, 375, 52, 260, 20, 244, 1, 69, 435, 63, 263, 226, 379, 280, 286, 15, 354, 287, 272, 270, 274, 336, 327, 343, 195, 359, 125, 55, 309, 386, 382, 89, 316, 285, 321, 161, 214, 420, 264, 136, 97, 415, 381, 328, 404, 258, 346, 401, 266, 76, 28, 203, 56, 47, 146, 131, 187, 37, 90, 91, 432, 426, 391, 365, 155, 38, 40, 373, 53, 256, 51, 104, 154, 180, 238, 72, 204, 253, 192, 102, 213, 395, 62, 352, 165, 413, 225, 129, 94, 423, 79, 123, 378, 121, 124, 73, 424, 219, 376, 99, 105, 113, 392, 211, 242, 19, 334, 188, 222, 26, 142, 368, 162, 332, 312, 157, 158, 10, 433, 428, 411, 295, 436, 329, 92, 394, 234, 196, 357, 235, 421, 363, 57, 361, 317, 34, 82, 174, 288, 167, 218, 100, 84, 58, 6, 119, 139, 351, 237, 345, 75, 88, 306, 377, 35, 324, 228, 33, 241, 330, 5, 405, 87, 205, 331, 229, 294, 153, 93, 279, 144, 183, 284, 412, 301, 283, 337, 353, 207, 98, 3, 269, 164, 406, 247, 347, 64, 417, 135, 318, 43, 255, 250, 128, 371, 110, 163, 308, 389, 236, 152, 240, 120, 133, 410, 17, 101, 171, 194, 86, 431, 268, 71, 2, 349, 223, 25, 416, 116, 137, 216, 299, 262, 130, 184, 149)  ORDER BY created_at desc\r\n  HABTM_Photos Load (0.4ms)  SELECT \"photos_plantings\".* FROM \"photos_plantings\"  WHERE \"photos_plantings\".\"planting_id\" IN (3, 2, 1)\r\n  CACHE (0.0ms)  SELECT \"crops\".* FROM \"crops\"  WHERE \"crops\".\"approval_status\" = 'approved'  ORDER BY random()\r\n  CACHE (0.0ms)  SELECT \"plantings\".* FROM \"plantings\"  WHERE \"plantings\".\"crop_id\" IN (239, 390, 80, 8, 292, 199, 227, 18, 78, 230, 307, 191, 13, 348, 340, 74, 366, 313, 54, 206, 172, 24, 335, 202, 61, 181, 178, 397, 70, 217, 208, 118, 399, 341, 251, 41, 140, 275, 319, 46, 233, 147, 193, 7, 49, 108, 370, 126, 111, 338, 243, 398, 265, 209, 127, 232, 273, 364, 48, 259, 186, 271, 221, 197, 138, 290, 150, 81, 231, 311, 342, 42, 215, 14, 212, 252, 169, 310, 143, 210, 278, 358, 407, 166, 344, 59, 45, 356, 408, 68, 151, 314, 177, 115, 176, 254, 107, 60, 323, 277, 189, 168, 333, 224, 16, 27, 106, 385, 291, 173, 30, 298, 109, 32, 85, 201, 12, 134, 245, 11, 374, 425, 402, 419, 246, 403, 434, 297, 303, 362, 293, 393, 360, 22, 159, 220, 430, 179, 388, 302, 50, 185, 83, 418, 36, 4, 326, 322, 198, 267, 67, 200, 369, 282, 325, 400, 320, 249, 422, 44, 339, 190, 384, 276, 96, 66, 355, 414, 383, 117, 315, 367, 21, 156, 304, 77, 261, 300, 429, 380, 23, 296, 160, 148, 122, 95, 39, 141, 289, 427, 114, 112, 103, 409, 145, 350, 372, 396, 65, 170, 175, 9, 387, 29, 31, 305, 132, 182, 257, 281, 248, 375, 52, 260, 20, 244, 1, 69, 435, 63, 263, 226, 379, 280, 286, 15, 354, 287, 272, 270, 274, 336, 327, 343, 195, 359, 125, 55, 309, 386, 382, 89, 316, 285, 321, 161, 214, 420, 264, 136, 97, 415, 381, 328, 404, 258, 346, 401, 266, 76, 28, 203, 56, 47, 146, 131, 187, 37, 90, 91, 432, 426, 391, 365, 155, 38, 40, 373, 53, 256, 51, 104, 154, 180, 238, 72, 204, 253, 192, 102, 213, 395, 62, 352, 165, 413, 225, 129, 94, 423, 79, 123, 378, 121, 124, 73, 424, 219, 376, 99, 105, 113, 392, 211, 242, 19, 334, 188, 222, 26, 142, 368, 162, 332, 312, 157, 158, 10, 433, 428, 411, 295, 436, 329, 92, 394, 234, 196, 357, 235, 421, 363, 57, 361, 317, 34, 82, 174, 288, 167, 218, 100, 84, 58, 6, 119, 139, 351, 237, 345, 75, 88, 306, 377, 35, 324, 228, 33, 241, 330, 5, 405, 87, 205, 331, 229, 294, 153, 93, 279, 144, 183, 284, 412, 301, 283, 337, 353, 207, 98, 3, 269, 164, 406, 247, 347, 64, 417, 135, 318, 43, 255, 250, 128, 371, 110, 163, 308, 389, 236, 152, 240, 120, 133, 410, 17, 101, 171, 194, 86, 431, 268, 71, 2, 349, 223, 25, 416, 116, 137, 216, 299, 262, 130, 184, 149)  ORDER BY created_at desc\r\n  CACHE (0.0ms)  SELECT \"photos_plantings\".* FROM \"photos_plantings\"  WHERE \"photos_plantings\".\"planting_id\" IN (3, 2, 1)\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/Growstuff/growstuff/issues/comments/202374509","html_url":"https://github.com/Growstuff/growstuff/pull/841#issuecomment-202374509","issue_url":"https://api.github.com/repos/Growstuff/growstuff/issues/841","id":202374509,"user":{"login":"coveralls","id":2354108,"avatar_url":"https://avatars.githubusercontent.com/u/2354108?v=3","gravatar_id":"","url":"https://api.github.com/users/coveralls","html_url":"https://github.com/coveralls","followers_url":"https://api.github.com/users/coveralls/followers","following_url":"https://api.github.com/users/coveralls/following{/other_user}","gists_url":"https://api.github.com/users/coveralls/gists{/gist_id}","starred_url":"https://api.github.com/users/coveralls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveralls/subscriptions","organizations_url":"https://api.github.com/users/coveralls/orgs","repos_url":"https://api.github.com/users/coveralls/repos","events_url":"https://api.github.com/users/coveralls/events{/privacy}","received_events_url":"https://api.github.com/users/coveralls/received_events","type":"User","site_admin":false},"created_at":"2016-03-28T12:50:52Z","updated_at":"2016-03-28T12:50:52Z","body":"\n[![Coverage Status](https://coveralls.io/builds/5567853/badge)](https://coveralls.io/builds/5567853)\n\nCoverage remained the same at 86.481% when pulling **b57cb581dd900f1a4ece59bfb0dba326740dd5f4 on CloCkWeRX:fix_840_performance** into **22e0e8fba0cf3d79c76994ea0b40f6d24678ad5a on Growstuff:dev**.\n"}}