refactor(api): read object visibility inside update tx; breathing-room nits
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -262,9 +262,16 @@ pub(crate) async fn update_object(
|
|||||||
|
|
||||||
let recording_date = req.recording_date.as_deref().map(parse_date).transpose()?;
|
let recording_date = req.recording_date.as_deref().map(parse_date).transpose()?;
|
||||||
|
|
||||||
// Read current visibility so the update preserves it — visibility changes only
|
let mut tx = state
|
||||||
// through the stepwise publish endpoint.
|
.db
|
||||||
let Some(current) = db::catalog::object_by_id(state.db.pool(), object_id)
|
.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
|
.await
|
||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
|
||||||
else {
|
else {
|
||||||
@@ -283,13 +290,6 @@ pub(crate) async fn update_object(
|
|||||||
visibility: current.visibility,
|
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)
|
let existed = db::catalog::update_object(&mut tx, actor(&auth.user), object_id, &input)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user