Lazy unlocks

Make a (course, user) pair's exercise unlocks computed lazily. This should get rid of the slowest phase of course refreshes. Also speeds up `courses/:id[.json]` somewhat.

This PR is probably easiest to review one commit at a time.

The first commits prepare for a background unlocking daemon but on second thought it doesn't seem necessary.