diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2022-03-03 12:57:21 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2022-03-03 12:57:38 +0100 |
commit | b832a38ca63a4bdc777291709baaad233e25e2a4 (patch) | |
tree | 0bd32c526e4c1aa47cdffbbfa20cb971166e7bd6 | |
parent | 6353dd156a9794499781b6f26be7b13b227b5628 (diff) | |
download | haven-b832a38ca63a4bdc777291709baaad233e25e2a4.tar.gz haven-b832a38ca63a4bdc777291709baaad233e25e2a4.tar.xz haven-b832a38ca63a4bdc777291709baaad233e25e2a4.zip |
hswg: parallelize rendering
-rw-r--r-- | hswg/main.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/hswg/main.go b/hswg/main.go index 9fe3fd7..65557c5 100644 --- a/hswg/main.go +++ b/hswg/main.go @@ -17,6 +17,7 @@ import ( "regexp" "sort" "strings" + "sync" "syscall" "time" @@ -121,7 +122,7 @@ type Entry struct { // Published returns the date when the entry was published, or nil if unknown. func (e *Entry) Published() *time.Time { - if d, _, err := e.Attributes.GetAsString("date"); err != nil { + if d, ok, err := e.Attributes.GetAsString("date"); !ok || err != nil { return nil } else if t, err := time.Parse(time.RFC3339, d); err == nil { return &t @@ -287,14 +288,25 @@ func writeIndex(path string, t *template.Template, func finalizeEntries(entries *map[string]*Entry, t *template.Template, indexPath string, indexT *template.Template) { + // The initial render of a large amount of entries is resource-intensive. + var wg sync.WaitGroup for name, e := range *entries { e.backlinks = map[string]bool{} - if e.raw == nil { + if e.raw != nil { + continue + } + + wg.Add(1) + go func(name string, e *Entry) { + defer wg.Done() if err := renderEntry(name, e); err != nil { log.Printf("%s: %s\n", name, err) } - } + }(name, e) } + + wg.Wait() + for name, e := range *entries { // Expand LinkWords anywhere between <tags>. // We want something like the inverse of Regexp.ReplaceAllStringFunc. |