1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-03 09:07:19 +00:00

Refactor request context (#32956)

Introduce RequestContext: is a short-lived context that is used to store
request-specific data.

RequestContext could be used to clean form tmp files, close context git
repo, and do some tracing in the future.

Then a lot of legacy code could be removed or improved. For example:
most `ctx.Repo.GitRepo.Close()` could be removed because the git repo
could be closed when the request is done.
This commit is contained in:
wxiaoguang
2024-12-24 11:43:57 +08:00
committed by GitHub
parent 781c6df40f
commit 6d5aa9218e
34 changed files with 379 additions and 422 deletions

View File

@ -4,7 +4,6 @@
package web
import (
gocontext "context"
"net/http"
"strings"
@ -1521,24 +1520,23 @@ func registerRoutes(m *web.Router) {
m.Group("/blob_excerpt", func() {
m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
}, func(ctx *context.Context) gocontext.CancelFunc {
}, func(ctx *context.Context) {
// FIXME: refactor this function, use separate routes for wiki/code
if ctx.FormBool("wiki") {
ctx.Data["PageIsWiki"] = true
repo.MustEnableWiki(ctx)
return nil
return
}
if ctx.Written() {
return nil
return
}
cancel := context.RepoRef()(ctx)
context.RepoRef()(ctx)
if ctx.Written() {
return cancel
return
}
repo.MustBeNotEmpty(ctx)
return cancel
})
m.Group("/media", func() {