FFFF One write path for the learning handlers: one transaction, one preamble · Issue #294 · alexbeeken/skrongle-mini · GitHub
[go: up one dir, main page]

Skip to content

One write path for the learning handlers: one transaction, one preamble #294

Backlog

Description

@alexbeeken

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_user sets u.tz (src/auth.rs:502), yet 14 handlers also take headers and call tz_offset_secs. conjugation_finish uses both (src/routes/games.rs:724, :735).
  • 6 * 3600 * 1000 written 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 NewWord structs 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") inside Db::call (routes/progress.rs ×4, routes/quiz.rs:306, routes/tutor.rs:423).

Fix, two PRs:

  1. Add Project::write(&state, |tx, ctx| …): one transaction, with ctx carrying the user, course, &ContentStore, time zone and now. It does the progress cache's take and put that record_answer_with does by hand (otherwise mastery::save inside a transaction forgets the cached map, src/mastery.rs:258-262). Move routes/progress.rs and routes/quiz.rs to it.
  2. Move sprint, guide, games and listening; delete the headers parameters; one MAX_ROUND_MS; one plausible().

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

  1. added
    review
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0