fix: write API posts in one transaction and fire RecordSaved after its commit

POST and PUT /_journal/api/v1/posts saved the row, then the categories, tags
and translations, and fired RecordSaved only when all succeeded. A failure
part-way left a committed row (possibly a new slug) with no event, so
subscribers such as an SEO plugin never created the redirect. The write now
runs in one lagoon transaction with the event emitted inside it.
This commit is contained in:
2026-10-27 15:35:07 +01:00
parent f5a0394d69
commit 62c75b1fc2
4 changed files with 55 additions and 24 deletions

View File

@@ -66,8 +66,8 @@ func snapshotPost(ctx context.Context, db *gorm.DB, post *models.Post, body map[
}
// postSavedEvent is the RecordSaved of an API write, which the handler
// fires with cabana.EmitRecordSaved once the write is committed (the API
// writes run outside a transaction, so at once). before is nil on create:
// fires with cabana.EmitRecordSaved inside the write's transaction, so it
// reaches subscribers once the write commits. before is nil on create:
// every column with a value and every submitted translation is then
// reported with a nil Old. Controller is "": the write did not go through an
// admin form.