fix(pull): read updated conversations from primary #107
No reviewers
Labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
codefloe/forgejo-codefloe!107
Loading…
Reference in a new issue
No description provided.
Delete branch "t3code/fix-review-read-consistency"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
db.WithMaster, a reusable primary-scoped database context that reuses an existing transaction and closes its session.LoadAttachmentscall inrenderConversation, which reran on the replica and overwrote the attachments already loaded on the primary.context.WebContextFromContextin the markup processor helper, so mentions and permalinks keep theDoerwhen rendering inside adb.WithMasterordb.WithTxcallback.engine.gohunk,context.gountouched, all new code and tests in_codefloefiles.Motivation
Forgejo's engine group routes autocommit reads to replicas.
Immediately after writing a review comment, replication lag can therefore make
FetchCodeConversationreturn an empty slice.The conversation template indexes the first comment, which then fails with a slice index out of range error even though the comment write succeeded.
This keeps ordinary reads on replicas and sends only the mutation response's conversation refetch to the primary.
Files
models/db/context_codefloe.go:WithMaster, built on the package's master engine likeWithTx.models/db/context_codefloe_test.go: stale replica vs primary read, error passthrough (typed errors stay assertable), transaction reuse.routers/web/repo/pull_review_codefloe.go:fetchCodeConversationFromPrimary, reports an empty result asErrCommentNotExist.routers/web/repo/pull_review_codefloe_test.go: empty conversation renders 404.routers/web/repo/pull_review.go: call the helper,NotFoundOrServerError, remove the duplicate attachment load.services/context/context_codefloe.go:WebContextFromContext.services/markup/processorhelper_codefloe_test.go: private user is mentionable from a wrapped web context.services/markup/processorhelper.go: useWebContextFromContextfor the twoDoerlookups.Testing
go vet -tags 'sqlite sqlite_unlock_notify' ./models/db ./routers/web/repo ./services/markup ./services/contextgo test -race -count=1 -tags 'sqlite sqlite_unlock_notify' ./models/db ./services/markup ./services/contextgo test -race -count=1 -tags 'sqlite sqlite_unlock_notify' ./routers/web/repo -run TestRenderConversationgolangci-lint runon the four packages with the pinnedgo1.26.7toolchain: only a pre-existingmodernizehit inrouters/web/repo/pull.go:977, untouched by this PR.git diff --check952fef1268d108267eb0d108267eb0f8ccfafc59