From 34e5754815c5ed2c087c176c668d60d087686e9f Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Tue, 2 Jun 2026 22:05:54 +0200 Subject: [PATCH] refactor(api): read object visibility inside update tx; breathing-room nits Co-Authored-By: Claude Sonnet 4.6 --- crates/api/src/admin_objects.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/api/src/admin_objects.rs b/crates/api/src/admin_objects.rs index 0b9bfa3..fb4c2fa 100644 --- a/crates/api/src/admin_objects.rs +++ b/crates/api/src/admin_objects.rs @@ -262,9 +262,16 @@ pub(crate) async fn update_object( let recording_date = req.recording_date.as_deref().map(parse_date).transpose()?; - // Read current visibility so the update preserves it — visibility changes only - // through the stepwise publish endpoint. - let Some(current) = db::catalog::object_by_id(state.db.pool(), object_id) + let mut tx = state + .db + .pool() + .begin() + .await + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; + + // Read current visibility inside the tx so the read and update are atomic — + // visibility changes only through the stepwise publish endpoint. + let Some(current) = db::catalog::object_by_id(&mut *tx, object_id) .await .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)? else { @@ -283,13 +290,6 @@ pub(crate) async fn update_object( visibility: current.visibility, }; - let mut tx = state - .db - .pool() - .begin() - .await - .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; - let existed = db::catalog::update_object(&mut tx, actor(&auth.user), object_id, &input) .await .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;