DemocracyClub / candidate_questions

BSD 3-Clause "New" or "Revised" License
1 stars 3 forks source link

Question assignment v2 #13

Closed dantheta closed 9 years ago

dantheta commented 9 years ago

Hiya -

I wanted to submit this one for review. Filling the open questions set is now a method on the candidate model, which is triggered by a post-save hook. When a candidate is saved (and participating is set to true), the oldest 10 unanswered questions will be set up for the candidate to answer. This can also be triggered for all participating candidates as a management script (perhaps for use by cron).

It had been suggested that the addition of a question could result in an allocation run (perhaps by using a post-save hook on the question model), but I'd be a little bit concerned about scaling to a large number of candidates or previously-answered questions when the addition of a new question would cause a bulk read of candidates and answers. I've taken a more cautious approach for now.

dantheta commented 9 years ago

All updated to use the proper settings convention.

EdwardBetts commented 9 years ago

I think that we don't need to create a blank answer for every question and candidate. With 3,846 candidates in the system and 100 questions we'll have 384,600 answers that are mostly empty. We should create the answer objects when a candidate answers a question. Then we don't have to worry about when to populate the answer table.

dantheta commented 9 years ago

It only creates 10 blank answer records (the number is the OPEN_QUESTIONS_TARGET value from config), and the routine is only run on candidates who have the participating flag set (or when they are saved).

This is to make sure that when a candidate views their questions list, the page responds in fixed time, since we've pre-allocated questions to them. A partial index would also help here, but I'm not sure if Django's modelling system supports them.

I was concerned that the query to retrieve all unanswered questions for a candidate would get slower as the number of questions in the system increases, and would be a bit wasteful for a page that the candidate would (hopefully) visit often!

Does that sound OK?

On Fri, Apr 10, 2015 at 02:29:01AM -0700, Edward Betts wrote:

I think that we don't need to create a blank answer for every question and candidate. With 3,846 candidates in the system and 100 questions we'll have 384,600 answers that are mostly empty. We should create the answer objects when a candidate answers a question. Then we don't have to worry about when to populate the answer table.


Reply to this email directly or view it on GitHub: https://github.com/DemocracyClub/candidate_questions/pull/13#issuecomment-91492584

EdwardBetts commented 9 years ago

I misunderstood how it worked. I created some questions, then loaded the 3,846 candidates from the CSV. An empty answer object was created for each combination of question and candidate. We could change it so answer objects are only created if the candidate is participating.

dantheta commented 9 years ago

Yes, you're right - I missed the test on the participating flag in the post-save hook on candidate, so adding questions and then loading candidates did the pre-fill on all candidates. I'll get that fixed.

Thanks!

On Fri, Apr 10, 2015 at 04:56:48AM -0700, Edward Betts wrote:

I misunderstood how it worked. I created some questions, then loaded the 3,846 candidates from the CSV. An empty answer object was created for each combination of question and candidate. We could change it so answer objects are only created if the candidate is participating.


Reply to this email directly or view it on GitHub: https://github.com/DemocracyClub/candidate_questions/pull/13#issuecomment-91531894