fix(db): skip UPDATE and audit on no-op object update (keep updated_at consistent)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+17
-15
@@ -188,6 +188,12 @@ pub async fn update_object(
|
|||||||
return Ok(false);
|
return Ok(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let changes = update_changes(&old.to_input(), input);
|
||||||
|
if changes.is_empty() {
|
||||||
|
// No-op: don't touch updated_at or the audit log.
|
||||||
|
return Ok(true);
|
||||||
|
}
|
||||||
|
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"UPDATE object SET \
|
"UPDATE object SET \
|
||||||
object_number = $2, object_name = $3, number_of_objects = $4, \
|
object_number = $2, object_name = $3, number_of_objects = $4, \
|
||||||
@@ -208,21 +214,17 @@ pub async fn update_object(
|
|||||||
.execute(&mut *conn)
|
.execute(&mut *conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let changes = update_changes(&old.to_input(), input);
|
audit::record(
|
||||||
|
&mut *conn,
|
||||||
if !changes.is_empty() {
|
&NewAuditEvent {
|
||||||
audit::record(
|
actor,
|
||||||
&mut *conn,
|
action: AuditAction::Updated,
|
||||||
&NewAuditEvent {
|
entity_type: ENTITY_TYPE.to_owned(),
|
||||||
actor,
|
entity_id: id.to_uuid(),
|
||||||
action: AuditAction::Updated,
|
changes,
|
||||||
entity_type: ENTITY_TYPE.to_owned(),
|
},
|
||||||
entity_id: id.to_uuid(),
|
)
|
||||||
changes,
|
.await?;
|
||||||
},
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user