bug in a nutshell
- generating a onestep quiz calls qdbm.qids_for_quiz_defn
- chapter.questions with category joins is returning duplicates. e.g. book id 7, chapter 2 returns [3388, 3601, 4200, 3348, 3288, 3483, 3376, 3284, 4096, 3427, 3656, 3301, 3543, 3316, 3601]
- need to rework to add uniq
new approach
- add uniq get ids with out dups
- shuffle
- pull num ids required from shuffles list
1.9.3p286 :047 > qids=qdbm.qids_for_quiz_defn(qd); p qids.count; p qids; p qids.uniq.count; p qids.uniq!
(0.5ms) SELECT `categories`.id FROM `categories` INNER JOIN `categories_quiz_definitions` ON `categories`.`id` = `categories_quiz_definitions`.`category_id` WHERE `categories_quiz_definitions`.`quiz_definition_id` = 15
Chapter Load (0.3ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 1 LIMIT 1
(0.2ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 76 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 0
[]
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 2 LIMIT 1
(3.6ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 15
[3388, 3601, 4200, 3348, 3288, 3483, 3376, 3284, 4096, 3427, 3656, 3301, 3543, 3316, 3601]
Chapter Load (0.4ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 3 LIMIT 1
(2.8ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 78 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 9
[3368, 4084, 3448, 4110, 3441, 4055, 3438, 4111, 4105]
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 4 LIMIT 1
(2.1ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 79 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 9
[3577, 3557, 3620, 3565, 3591, 3546, 10896, 3576, 3607]
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 5 LIMIT 1
(2.3ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 80 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 15
[2940, 3064, 2978, 3000, 3042, 2926, 2961, 10847, 3048, 10948, 3026, 2942, 10949, 3011, 4129]
Chapter Load (0.3ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 6 LIMIT 1
(1.7ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 81 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 10
[3673, 3753, 3659, 3706, 3659, 3719, 3663, 3673, 3738, 3660]
Chapter Load (0.3ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 7 LIMIT 1
(1.8ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 82 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 8
[3724, 3936, 3904, 3904, 3940, 4043, 3933, 3208]
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 8 LIMIT 1
(3.2ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 83 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 15
[3081, 4224, 3272, 3222, 3127, 3197, 3195, 3186, 3266, 3172, 3228, 3080, 3246, 3162, 3198]
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 9 LIMIT 1
(3.9ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 84 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 15
[3809, 3801, 3784, 3843, 3855, 3812, 3814, 3790, 3783, 3990, 3994, 3772, 3804, 3900, 3817]
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 10 LIMIT 1
(1.0ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 85 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 4
[3943, 4035, 3974, 4029]
100 qids pulled from QuestionDatabaseMiner
[3388, 3601, 4200, 3348, 3288, 3483, 3376, 3284, 4096, 3427, 3656, 3301, 3543, 3316, 3601, 3368, 4084, 3448, 4110, 3441, 4055, 3438, 4111, 4105, 3577, 3557, 3620, 3565, 3591, 3546, 10896, 3576, 3607, 2940, 3064, 2978, 3000, 3042, 2926, 2961, 10847, 3048, 10948, 3026, 2942, 10949, 3011, 4129, 3673, 3753, 3659, 3706, 3659, 3719, 3663, 3673, 3738, 3660, 3724, 3936, 3904, 3904, 3940, 4043, 3933, 3208, 3081, 4224, 3272, 3222, 3127, 3197, 3195, 3186, 3266, 3172, 3228, 3080, 3246, 3162, 3198, 3809, 3801, 3784, 3843, 3855, 3812, 3814, 3790, 3783, 3990, 3994, 3772, 3804, 3900, 3817, 3943, 4035, 3974, 4029]
use uniq! to get rid of duplicates, only 96 remain
[3388, 3601, 4200, 3348, 3288, 3483, 3376, 3284, 4096, 3427, 3656, 3301, 3543, 3316, 3368, 4084, 3448, 4110, 3441, 4055, 3438, 4111, 4105, 3577, 3557, 3620, 3565, 3591, 3546, 10896, 3576, 3607, 2940, 3064, 2978, 3000, 3042, 2926, 2961, 10847, 3048, 10948, 3026, 2942, 10949, 3011, 4129, 3673, 3753, 3659, 3706, 3719, 3663, 3738, 3660, 3724, 3936, 3904, 3940, 4043, 3933, 3208, 3081, 4224, 3272, 3222, 3127, 3197, 3195, 3186, 3266, 3172, 3228, 3080, 3246, 3162, 3198, 3809, 3801, 3784, 3843, 3855, 3812, 3814, 3790, 3783, 3990, 3994, 3772, 3804, 3900, 3817, 3943, 4035, 3974, 4029]
the initial array, sorted to help ferret out the duplicates
[2926, 2940, 2942, 2961, 2978, 3000, 3011, 3026, 3042, 3048, 3064, 3080, 3081, 3127, 3162, 3172, 3186, 3195, 3197, 3198, 3208, 3222, 3228, 3246, 3266, 3272, 3284, 3288, 3301, 3316, 3348, 3368, 3376, 3388, 3427, 3438, 3441, 3448, 3483, 3543, 3546, 3557, 3565, 3576, 3577, 3591, 3601, 3601, 3607, 3620, 3656, 3659, 3659, 3660, 3663, 3673, 3673, 3706, 3719, 3724, 3738, 3753, 3772, 3783, 3784, 3790, 3801, 3804, 3809, 3812, 3814, 3817, 3843, 3855, 3900, 3904, 3904, 3933, 3936, 3940, 3943, 3974, 3990, 3994, 4029, 4035, 4043, 4055, 4084, 4096, 4105, 4110, 4111, 4129, 4200, 4224, 10847, 10896, 10948, 10949]
##################################################
# chapter questions
##################################################
1.9.3p286 :067 > chapter=Book.find(7).chapters.find_by_chapnum(2)
1.9.3p286 :067 > chapter.questions.pluck("questions.id")
(0.9ms) SELECT questions.id FROM `questions` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77
=> [3274, 3275, 3276, 3277, 3278, 3279, 3280, 3281, 3282, 3283, 3284, 3285, 3286, 3287, 3288, 3289, 3290, 3291, 3292, 3293, 3294, 3295, 3296, 3297, 3298, 3299, 3300, 3301, 3302, 3303, 3304, 3305, 3306, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324, 3325, 3326, 3327, 3328, 3329, 3330, 3331, 3332, 3333, 3334, 3335, 3336, 3337, 3338, 3339, 3340, 3341, 3342, 3343, 3344, 3345, 3346, 3347, 3348, 3349, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3370, 3371, 3373, 3374, 3375, 3376, 3377, 3378, 3379, 3380, 3381, 3382, 3383, 3384, 3385, 3386, 3387, 3388, 3389, 3390, 3391, 3392, 3393, 3394, 3395, 3396, 3397, 3398, 3399, 3400, 3401, 3402, 3403, 3404, 3409, 3411, 3413, 3414, 3415, 3416, 3417, 3418, 3419, 3420, 3421, 3422, 3423, 3424, 3425, 3426, 3427, 3428, 3429, 3430, 3431, 3432, 3480, 3481, 3482, 3483, 3484, 3485, 3491, 3492, 3494, 3509, 3525, 3526, 3527, 3528, 3529, 3543, 3601, 3609, 3623, 3633, 3636, 3637, 3638, 3639, 3640, 3642, 3652, 3653, 3654, 3655, 3656, 3657, 3890, 3891, 3893, 3894, 3895, 3896, 3897, 3898, 3992, 4002, 4003, 4016, 4017, 4018, 4019, 4020, 4021, 4022, 4023, 4024, 4025, 4057, 4058, 4059, 4076, 4077, 4078, 4079, 4080, 4081, 4082, 4083, 4085, 4086, 4087, 4088, 4089, 4090, 4091, 4092, 4094, 4096, 4097, 4098, 4200, 4201]
217 records
1.9.3p286 :092 > Book.find(7).chapters.find_by_chapnum(2).questions.pluck("questions.id").count
=> 217
no duplicates
1.9.3p286 :079 > Book.find(7).chapters.find_by_chapnum(2).questions.pluck("questions.id").uniq!
=> nil
chap 2
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 2 LIMIT 1
(3.7ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 15
##################################################
# adding the category where clause
##################################################
1.9.3p286 :101 > Book.find(7).chapters.find_by_chapnum(2).questions.joins(:categories).where("category_id in (3,4,10,11,12,15,17,19)").where(deprecated:false).pluck("questions.id")
Book Load (0.3ms) SELECT `books`.* FROM `books` WHERE `books`.`id` = 7 LIMIT 1
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 2 LIMIT 1
(3.8ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19))
=> [3274, 3278, 3279, 3280, 3281, 3282, 3284, 3291, 3292, 3301, 3302, 3304, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324, 3325, 3326, 3327, 3328, 3330, 3331, 3334, 3344, 3345, 3346, 3347, 3348, 3349, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3480, 3481, 3482, 3483, 3484, 3485, 3543, 3601, 4096, 4097, 4098, 4200, 3275, 3277, 3283, 3285, 3286, 3287, 3288, 3289, 3290, 3293, 3294, 3295, 3296, 3297, 3298, 3299, 3300, 3303, 3305, 3306, 3329, 3332, 3333, 3335, 3336, 3337, 3338, 3339, 3340, 3341, 3342, 3343, 3609, 3278, 3281, 3282, 3284, 3299, 3304, 3306, 3308, 3309, 3310, 3311, 3331, 3334, 3348, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3414, 3415, 3416, 3417, 3480, 3481, 3482, 3483, 3484, 3485, 3509, 3601, 3638, 3639, 3640, 3642, 3992, 4096, 4097, 3274, 3278, 3279, 3280, 3281, 3282, 3284, 3291, 3292, 3301, 3302, 3304, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324, 3325, 3326, 3327, 3328, 3330, 3331, 3334, 3344, 3345, 3346, 3347, 3348, 3349, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3480, 3481, 3482, 3483, 3484, 3485, 3543, 3601, 4096, 4097, 4098, 4200, 3418, 3419, 3420, 3421, 3422, 3423, 3424, 3425, 3426, 3427, 3428, 3429, 3430, 3431, 3432, 3525, 3526, 3527, 3528, 3529, 3652, 3653, 3654, 3655, 3656, 3657, 4002, 4003, 4016, 4017, 4018, 4019, 4020, 4021, 4022, 4023, 4024, 4025, 3278, 3280, 3284, 3292, 3301, 3302, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3323, 3324, 3325, 3326, 3327, 3331, 3345, 3346, 3347, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3543, 3601, 4057, 4058, 4059, 4076, 4077, 4078, 4079, 4080, 4081, 4082, 4083, 4085, 4094, 4096, 4097, 3276, 3370, 3371, 3373, 3374, 3375, 3376, 3377, 3378, 3379, 3380, 3381, 3382, 3383, 3384, 3385, 3386, 3387, 3388, 3389, 3390, 3391, 3392, 3393, 3394, 3395, 3396, 3397, 3398, 3399, 3400, 3401, 3402, 3403, 3404, 3409, 3411, 3413, 3491, 3492, 3494, 3623, 3633, 3636, 3637, 3890, 3891, 3893, 3894, 3895, 3896, 3897, 3898, 4201, 3278, 3279, 3280, 3284, 3292, 3301, 3302, 3304, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324, 3325, 3326, 3327, 3328, 3330, 3331, 3334, 3345, 3346, 3347, 3348, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3543, 3601, 4086, 4087, 4088, 4089, 4090, 4091, 4092, 4096, 4097, 4200]
1.9.3p286 :102 > Book.find(7).chapters.find_by_chapnum(2).questions.joins(:categories).where("category_id in (3,4,10,11,12,15,17,19)").where(deprecated:false).pluck("questions.id").count
Book Load (0.3ms) SELECT `books`.* FROM `books` WHERE `books`.`id` = 7 LIMIT 1
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 2 LIMIT 1
(3.7ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19))
=> 393
##################################################
# duplicates related to the join
##################################################
http://stackoverflow.com/questions/38549/difference-between-inner-and-outer-joins
e.g.
3279 cfi 6506 PLT477 2 5 AIR, LSA, WSC An airplane would have a tendency
3279 cfi 6506 PLT477 2 5 AIR, LSA, WSC An airplane would have a tendency
3279 cfi 6506 PLT477 2 5 AIR, LSA, WSC An airplane would have a tendency
3280 cfi 6507 PLT242 2 4 AIR, LSA, WSC, PPC When considering the forces
3280 cfi 6507 PLT242 2 4 AIR, LSA, WSC, PPC When considering the forces
3280 cfi 6507 PLT242 2 4 AIR, LSA, WSC, PPC When considering the forces
3280 cfi 6507 PLT242 2 4 AIR, LSA, WSC, PPC When considering the forces
##################################################
# resolve with uniq
##################################################
1.9.3p286 :105 > Book.find(7).chapters.find_by_chapnum(2).questions.joins(:categories).where("category_id in (3,4,10,11,12,15,17,19)").where(deprecated:false).pluck("questions.id").uniq
Book Load (0.3ms) SELECT `books`.* FROM `books` WHERE `books`.`id` = 7 LIMIT 1
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 2 LIMIT 1
(3.8ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19))
=> [3274, 3278, 3279, 3280, 3281, 3282, 3284, 3291, 3292, 3301, 3302, 3304, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324, 3325, 3326, 3327, 3328, 3330, 3331, 3334, 3344, 3345, 3346, 3347, 3348, 3349, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3480, 3481, 3482, 3483, 3484, 3485, 3543, 3601, 4096, 4097, 4098, 4200, 3275, 3277, 3283, 3285, 3286, 3287, 3288, 3289, 3290, 3293, 3294, 3295, 3296, 3297, 3298, 3299, 3300, 3303, 3305, 3306, 3329, 3332, 3333, 3335, 3336, 3337, 3338, 3339, 3340, 3341, 3342, 3343, 3609, 3414, 3415, 3416, 3417, 3509, 3638, 3639, 3640, 3642, 3992, 3418, 3419, 3420, 3421, 3422, 3423, 3424, 3425, 3426, 3427, 3428, 3429, 3430, 3431, 3432, 3525, 3526, 3527, 3528, 3529, 3652, 3653, 3654, 3655, 3656, 3657, 4002, 4003, 4016, 4017, 4018, 4019, 4020, 4021, 4022, 4023, 4024, 4025, 4057, 4058, 4059, 4076, 4077, 4078, 4079, 4080, 4081, 4082, 4083, 4085, 4094, 3276, 3370, 3371, 3373, 3374, 3375, 3376, 3377, 3378, 3379, 3380, 3381, 3382, 3383, 3384, 3385, 3386, 3387, 3388, 3389, 3390, 3391, 3392, 3393, 3394, 3395, 3396, 3397, 3398, 3399, 3400, 3401, 3402, 3403, 3404, 3409, 3411, 3413, 3491, 3492, 3494, 3623, 3633, 3636, 3637, 3890, 3891, 3893, 3894, 3895, 3896, 3897, 3898, 4201, 4086, 4087, 4088, 4089, 4090, 4091, 4092]
1.9.3p286 :106 > Book.find(7).chapters.find_by_chapnum(2).questions.joins(:categories).where("category_id in (3,4,10,11,12,15,17,19)").where(deprecated:false).pluck("questions.id").uniq.count
Book Load (0.4ms) SELECT `books`.* FROM `books` WHERE `books`.`id` = 7 LIMIT 1
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 2 LIMIT 1
(3.7ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19))
=> 217