hswg: parallelize rendering
This commit is contained in:
parent
6353dd156a
commit
b832a38ca6
18
hswg/main.go
18
hswg/main.go
@ -17,6 +17,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -121,7 +122,7 @@ type Entry struct {
|
|||||||
|
|
||||||
// Published returns the date when the entry was published, or nil if unknown.
|
// Published returns the date when the entry was published, or nil if unknown.
|
||||||
func (e *Entry) Published() *time.Time {
|
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
|
return nil
|
||||||
} else if t, err := time.Parse(time.RFC3339, d); err == nil {
|
} else if t, err := time.Parse(time.RFC3339, d); err == nil {
|
||||||
return &t
|
return &t
|
||||||
@ -287,14 +288,25 @@ func writeIndex(path string, t *template.Template,
|
|||||||
|
|
||||||
func finalizeEntries(entries *map[string]*Entry, t *template.Template,
|
func finalizeEntries(entries *map[string]*Entry, t *template.Template,
|
||||||
indexPath string, indexT *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 {
|
for name, e := range *entries {
|
||||||
e.backlinks = map[string]bool{}
|
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 {
|
if err := renderEntry(name, e); err != nil {
|
||||||
log.Printf("%s: %s\n", name, err)
|
log.Printf("%s: %s\n", name, err)
|
||||||
}
|
}
|
||||||
|
}(name, e)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
for name, e := range *entries {
|
for name, e := range *entries {
|
||||||
// Expand LinkWords anywhere between <tags>.
|
// Expand LinkWords anywhere between <tags>.
|
||||||
// We want something like the inverse of Regexp.ReplaceAllStringFunc.
|
// We want something like the inverse of Regexp.ReplaceAllStringFunc.
|
||||||
|
Loading…
Reference in New Issue
Block a user