Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ShaExistCache to RenderContext
  • Loading branch information
6543 committed Jun 18, 2021
commit 76632392b1ecd3e825fe61dd42c0180e45fe2f76
8 changes: 5 additions & 3 deletions modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,9 @@ func sha1CurrentPatternProcessor(ctx *RenderContext, node *html.Node) {

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

// check cache first
exist, inCache := cache[hash]
exist, inCache := ctx.ShaExistCache[hash]
if !inCache {
if ctx.GitRepo == nil {
var err error
Expand All @@ -1033,7 +1035,7 @@ func sha1CurrentPatternProcessor(ctx *RenderContext, node *html.Node) {
}

exist = ctx.GitRepo.IsObjectExist(hash)
cache[hash] = exist
ctx.ShaExistCache[hash] = exist
}

if !exist {
Expand Down
25 changes: 15 additions & 10 deletions modules/markup/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,25 @@ 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
GitRepo *git.Repository
cancelFn func()
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 || ctx.cancelFn == nil {
if ctx == nil {
return
}
ctx.ShaExistCache = map[string]bool{}
if ctx.cancelFn == nil {
return
}
ctx.cancelFn()
Expand Down