summaryrefslogtreecommitdiffstats
path: root/modules/markup/renderer.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-06-20 23:39:12 +0100
committerGitHub <noreply@github.com>2021-06-21 00:39:12 +0200
commit196593e2e996aa4a59547629b870701f2b001d9b (patch)
treee9d5f63b07c54cdd74eecb53322b839abdfd979c /modules/markup/renderer.go
parent23358bc55de67be132e3858a5d40f25dbdd0a769 (diff)
downloadgitea-196593e2e996aa4a59547629b870701f2b001d9b.tar.gz
gitea-196593e2e996aa4a59547629b870701f2b001d9b.zip
More efficiently parse shas for shaPostProcessor (#16101)
* More efficiently parse shas for shaPostProcessor The shaPostProcessor currently repeatedly calls git rev-parse --verify on both backends which is fine if there is only one thing that matches a sha - however if there are multiple things then this becomes wildly inefficient. This PR provides functions for both backends which are much faster to use. Fix #16092 * Add ShaExistCache to RenderContext Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'modules/markup/renderer.go')
-rw-r--r--modules/markup/renderer.go46
1 files changed, 39 insertions, 7 deletions
diff --git a/modules/markup/renderer.go b/modules/markup/renderer.go
index 5d35bd5a67..d60c8ad710 100644
--- a/modules/markup/renderer.go
+++ b/modules/markup/renderer.go
@@ -13,6 +13,7 @@ import (
"strings"
"sync"
+ "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
)
@@ -35,13 +36,44 @@ func Init() {
// RenderContext represents a render context
type RenderContext struct {
- Ctx context.Context
- Filename string
- Type string
- IsWiki bool
- URLPrefix string
- Metas map[string]string
- DefaultLink string
+ Ctx context.Context
+ Filename string
+ Type string
+ IsWiki bool
+ URLPrefix string
+ Metas map[string]string
+ DefaultLink string
+ GitRepo *git.Repository
+ ShaExistCache map[string]bool
+ cancelFn func()
+}
+
+// Cancel runs any cleanup functions that have been registered for this Ctx
+func (ctx *RenderContext) Cancel() {
+ if ctx == nil {
+ return
+ }
+ ctx.ShaExistCache = map[string]bool{}
+ if ctx.cancelFn == nil {
+ return
+ }
+ ctx.cancelFn()
+}
+
+// AddCancel adds the provided fn as a Cleanup for this Ctx
+func (ctx *RenderContext) AddCancel(fn func()) {
+ if ctx == nil {
+ return
+ }
+ oldCancelFn := ctx.cancelFn
+ if oldCancelFn == nil {
+ ctx.cancelFn = fn
+ return
+ }
+ ctx.cancelFn = func() {
+ defer oldCancelFn()
+ fn()
+ }
}
// Renderer defines an interface for rendering markup file to HTML