From 84a7728c6bb140f5c43c7c01f5dda0a57beb05a3 Mon Sep 17 00:00:00 2001 From: DedLad Date: Tue, 9 Apr 2024 15:56:41 +0530 Subject: [PATCH] parallelized RenderTags --- pkg/engine/anna_engine.go | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/pkg/engine/anna_engine.go b/pkg/engine/anna_engine.go index 37d4305..daf6e31 100644 --- a/pkg/engine/anna_engine.go +++ b/pkg/engine/anna_engine.go @@ -9,6 +9,7 @@ import ( "slices" "sort" "strings" + "sync" "time" "github.com/acmpesuecc/anna/pkg/helpers" @@ -47,20 +48,31 @@ func (e *Engine) RenderTags(fileOutPath string, templ *template.Template) { e.ErrorLogger.Fatal(err) } + // Create a wait group to wait for all goroutines to finish + var wg sync.WaitGroup + // Rendering the subpages with merged tagged posts for tag, taggedTemplates := range e.TagsMap { - pagePath := "tags/" + tag - templateData := parser.TemplateData{ - FilenameWithoutExtension: tag, - Layout: e.LayoutConfig, - Frontmatter: parser.Frontmatter{ - Title: tag, - }, - SpecificTagTemplates: taggedTemplates, - } - - e.RenderPage(fileOutPath, template.URL(pagePath), templateData, templ, "tag-subpage") - } + wg.Add(1) + go func(tag string, taggedTemplates []parser.TemplateData) { + defer wg.Done() + + pagePath := "tags/" + tag + templateData := parser.TemplateData{ + FilenameWithoutExtension: tag, + Layout: e.LayoutConfig, + Frontmatter: parser.Frontmatter{ + Title: tag, + }, + SpecificTagTemplates: taggedTemplates, + } + + e.RenderPage(fileOutPath, template.URL(pagePath), templateData, templ, "tag-subpage") + }(tag, taggedTemplates) + } + + // Wait for all goroutines to finish + wg.Wait() } func (e *Engine) GenerateJSONIndex(outFilePath string) {