Repository navigation
Description
Impact: medium for writes; high for consistency. Two reviewers reached the same place from different sides.
Several commits per click. Only /api/answer (mastery::record_answer_with) and the lesson page (src/routes/pages.rs:740) use one transaction. /api/sprint/check (src/routes/sprint.rs:341-372), the most frequent write on a phone, runs about 12 implicit transactions for a five-word exercise. With WAL each one appends its own frames, so the log grows several times faster and checkpoints come sooner. A failure midway leaves effort logged without the answer. Same shape in routes/guide.rs:446-450, routes/games.rs:337-344, :731-732, :864-865, :960-961, routes/listening.rs:257-264, routes/vocab.rs:285-287, routes/progress.rs:49-50, :342-343, :412-418, routes/sprint.rs:455-470. lesson_check (routes/quiz.rs:293-331) makes 4 Db::calls for one click. games::record_activity_at (src/games.rs:405-415) and courses::delete_course (src/courses.rs:1041) write several tables with no transaction.
The same preamble, drifting:
- Two sources for the time zone.
resolve_usersetsu.tz(src/auth.rs:502), yet 14 handlers also takeheadersand calltz_offset_secs.conjugation_finishuses both (src/routes/games.rs:724,:735). 6 * 3600 * 1000written 8 times.- Three plausibility checks with different bounds:
routes/progress.rs:83(≤200),routes/sprint.rs:426(≤200 plus duration),routes/games.rs:718(≤500). - Two
NewWordstructs and two copies of the mapping (routes/quiz.rs:362,414,routes/sprint.rs:312,376). - A re-lookup that can panic. Six sites clone a lesson id, then call
course.lesson_by_id(&id).expect("lesson exists")insideDb::call(routes/progress.rs×4,routes/quiz.rs:306,routes/tutor.rs:423).
Fix, two PRs:
- Add
Project::write(&state, |tx, ctx| …): one transaction, withctxcarrying the user, course,&ContentStore, time zone and now. It does the progress cache's take and put thatrecord_answer_withdoes by hand (otherwisemastery::saveinside a transaction forgets the cached map,src/mastery.rs:258-262). Moveroutes/progress.rsandroutes/quiz.rsto it. - Move sprint, guide, games and listening; delete the
headersparameters; oneMAX_ROUND_MS; oneplausible().
Before either: a table-driven router test over the finish endpoints (sprint, guide step, games, listening, lesson-check, practice-finish) that asserts the lesson_passes and activity_log rows. Today only /api/answer is posted by path in src/routes/tests.rs; the rest is covered only by browser specs.
From the code review of 24 November 2026. Line numbers are as of 0.5.0 (2547b36).
Activity