refactor: Drop redundant author re-fetches on the post write paths #44

Merged
rosa merged 1 commit from refactor/no-author-refetch into main 2026-07-03 01:02:30 +00:00
Owner

Closes #37.

The post write paths fetched the author from the repository when the caller already held that User:

  • update_post and delete_post verified current_user.id() == post.user_id(), then fetched the author by the post's user_id — after that check, the author is current_user.
  • create_post fetched the author by id when both callers (the web handler via AuthUser, and micropub_create via auth.user) already held the User.

Changes

  • update_post / delete_post: the author is current_user, bound with a one-line comment stating why; the find_user_by_id round-trip and its impossible "Post author not found" error branch are gone.
  • create_post takes author: &User instead of &UserId; the web handler passes &current_user and micropub_create passes &auth.user.
  • The domain test helpers (make_post and the direct create_post calls) pass the User they already had from register.

Each post write saves one repository round-trip.

Verification

mise run ci passes: clippy -D warnings, fmt, sqlx prepare check, all 151 domain tests and the integration suite (which covers web + Micropub create/update/delete end to end, including the webmention dispatch that consumes the author).

Closes #37. The post write paths fetched the author from the repository when the caller already held that `User`: - `update_post` and `delete_post` verified `current_user.id() == post.user_id()`, then fetched the author by the post's `user_id` — after that check, the author **is** `current_user`. - `create_post` fetched the author by id when both callers (the web handler via `AuthUser`, and `micropub_create` via `auth.user`) already held the `User`. ## Changes - `update_post` / `delete_post`: the author is `current_user`, bound with a one-line comment stating why; the `find_user_by_id` round-trip and its impossible "Post author not found" error branch are gone. - `create_post` takes `author: &User` instead of `&UserId`; the web handler passes `&current_user` and `micropub_create` passes `&auth.user`. - The domain test helpers (`make_post` and the direct `create_post` calls) pass the `User` they already had from `register`. Each post write saves one repository round-trip. ## Verification `mise run ci` passes: clippy `-D warnings`, fmt, sqlx prepare check, all 151 domain tests and the integration suite (which covers web + Micropub create/update/delete end to end, including the webmention dispatch that consumes the author).
refactor: Drop redundant author re-fetches on the post write paths
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
6b250a97a9
update_post and delete_post verified current_user owns the post, then
fetched the author by the post's user_id — after that check the author
is current_user. create_post fetched the author by id when both callers
(the web handler and micropub_create) already held the User.

Use current_user directly on the update/delete paths and take &User in
create_post. Each write saves a repository round-trip and loses an
impossible "Post author not found" error branch.

Closes #37
rosa merged commit c21237479f into main 2026-07-03 01:02:30 +00:00
rosa deleted branch refactor/no-author-refetch 2026-07-03 01:02:31 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rosa/vernier!44
No description provided.