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

Closed
opened 2026-07-03 00:09:54 +00:00 by rosa · 0 comments
Owner

Problem

The post write paths fetch the author from the repository when the caller already holds that User:

  • update_post (crates/domain/src/services.rs:1006-1016) verifies current_user.id() == old_post.user_id(), then fetches the author by old_post.user_id() — after that check, the author is current_user.
  • delete_post (services.rs:1052-1062) — same pattern.
  • create_post (services.rs:499-505) fetches the author by user_id, but both callers (the web handler via AuthUser, and micropub_create via auth.user) already hold the User.

Proposal

  • update_post / delete_post: drop the find_user_by_id round-trip and use current_user as the author for post_source_url.
  • create_post: take &User instead of &UserId.

Each change removes a DB round-trip per write and an impossible "Post author not found" error branch.

## Problem The post write paths fetch the author from the repository when the caller already holds that `User`: - `update_post` (`crates/domain/src/services.rs:1006-1016`) verifies `current_user.id() == old_post.user_id()`, then fetches the author by `old_post.user_id()` — after that check, the author **is** `current_user`. - `delete_post` (`services.rs:1052-1062`) — same pattern. - `create_post` (`services.rs:499-505`) fetches the author by `user_id`, but both callers (the web handler via `AuthUser`, and `micropub_create` via `auth.user`) already hold the `User`. ## Proposal - `update_post` / `delete_post`: drop the `find_user_by_id` round-trip and use `current_user` as the author for `post_source_url`. - `create_post`: take `&User` instead of `&UserId`. Each change removes a DB round-trip per write and an impossible "Post author not found" error branch.
rosa added reference refactor/no-author-refetch 2026-07-03 01:01:33 +00:00
rosa 2026-07-03 01:01:40 +00:00
Sign in to join this conversation.
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#37
No description provided.