Skip to content

Commit 7663239

Browse files
committed
Add ShaExistCache to RenderContext
1 parent 797f707 commit 7663239

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

modules/markup/html.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,9 @@ func sha1CurrentPatternProcessor(ctx *RenderContext, node *html.Node) {
997997

998998
start := 0
999999
next := node.NextSibling
1000-
cache := make(map[string]bool)
1000+
if ctx.ShaExistCache == nil {
1001+
ctx.ShaExistCache = make(map[string]bool)
1002+
}
10011003
for node != nil && node != next && start < len(node.Data) {
10021004
m := sha1CurrentPattern.FindStringSubmatchIndex(node.Data[start:])
10031005
if m == nil {
@@ -1017,7 +1019,7 @@ func sha1CurrentPatternProcessor(ctx *RenderContext, node *html.Node) {
10171019
// a commit in the repository before making it a link.
10181020

10191021
// check cache first
1020-
exist, inCache := cache[hash]
1022+
exist, inCache := ctx.ShaExistCache[hash]
10211023
if !inCache {
10221024
if ctx.GitRepo == nil {
10231025
var err error
@@ -1033,7 +1035,7 @@ func sha1CurrentPatternProcessor(ctx *RenderContext, node *html.Node) {
10331035
}
10341036

10351037
exist = ctx.GitRepo.IsObjectExist(hash)
1036-
cache[hash] = exist
1038+
ctx.ShaExistCache[hash] = exist
10371039
}
10381040

10391041
if !exist {

modules/markup/renderer.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,25 @@ func Init() {
3636

3737
// RenderContext represents a render context
3838
type RenderContext struct {
39-
Ctx context.Context
40-
Filename string
41-
Type string
42-
IsWiki bool
43-
URLPrefix string
44-
Metas map[string]string
45-
DefaultLink string
46-
GitRepo *git.Repository
47-
cancelFn func()
39+
Ctx context.Context
40+
Filename string
41+
Type string
42+
IsWiki bool
43+
URLPrefix string
44+
Metas map[string]string
45+
DefaultLink string
46+
GitRepo *git.Repository
47+
ShaExistCache map[string]bool
48+
cancelFn func()
4849
}
4950

5051
// Cancel runs any cleanup functions that have been registered for this Ctx
5152
func (ctx *RenderContext) Cancel() {
52-
if ctx == nil || ctx.cancelFn == nil {
53+
if ctx == nil {
54+
return
55+
}
56+
ctx.ShaExistCache = map[string]bool{}
57+
if ctx.cancelFn == nil {
5358
return
5459
}
5560
ctx.cancelFn()

0 commit comments

Comments
 (0)