mwalsh2020 / lsat-cracked

1 stars 0 forks source link

Quiz Question performance Query Object #195

Closed caioertai closed 3 years ago

caioertai commented 3 years ago

Closes #167

Initialization

Should be initialized with a quiz question active record relation. I'm leaving it loose so we can decide later (maybe in another object) what quiz questions are we using from the user.

About the test

I left it just as initialization check for now, since I was a bit undecided on the interface. I'll update it later.

Interface example:

performance = QuizQuestion::PerformanceQuery.new(current_user.quiz_questions)

performance.tags
# => [#<Tag::Performance:0x000055a8dee4d220 @correct_count=nil, @id=1, @slug="lsat-premium", @total_count=1>,
 #<Tag::Performance:0x000055a8dee4caa0 @correct_count=22, @id=2, @slug="true-false", @total_count=34>]

performance.tags.first
# => #<Tag::Performance:0x000055a8dee4d220 @correct_count=nil, @id=1, @slug="lsat-premium", @total_count=1>
performance.tags.first.value
# => 0.0

performance.tags.second.value
# => 0.6470588235294118
performance.tags.second.slug
# => "true-false"
caioertai commented 3 years ago

@jamiesonreinhard

I could have gone a bit harder on the query and actually returned to whole thing in just one query, without any (although simple right now) in-memory iteration. I thought it was going to over-complicate, tho, by a lot, something that we might change in the near future. This should be good enough for a loooong time.

If anything, the best piece of optimization we could have is a daily cache for the user info (I don't think we should be updating this data more than once a day anyway).