refactor: render segment text in sequence

This commit is contained in:
Jan De Dobbeleer 2024-08-05 14:28:47 +02:00 committed by Jan De Dobbeleer
parent 9e1942035f
commit 0853a527a7
3 changed files with 6 additions and 18 deletions

View file

@ -79,7 +79,6 @@ func (b *Block) executeSegmentLogic() {
} }
b.setEnabledSegments() b.setEnabledSegments()
b.setSegmentsText()
} }
func (b *Block) setEnabledSegments() { func (b *Block) setEnabledSegments() {
@ -94,15 +93,3 @@ func (b *Block) setEnabledSegments() {
}(segment) }(segment)
} }
} }
func (b *Block) setSegmentsText() {
wg := sync.WaitGroup{}
wg.Add(len(b.Segments))
defer wg.Wait()
for _, segment := range b.Segments {
go func(s *Segment) {
defer wg.Done()
s.setText()
}(segment)
}
}

View file

@ -60,7 +60,6 @@ type Segment struct {
CacheDuration cache.Duration `json:"cache_duration,omitempty" toml:"cache_duration,omitempty"` CacheDuration cache.Duration `json:"cache_duration,omitempty" toml:"cache_duration,omitempty"`
Enabled bool `json:"-" toml:"-"` Enabled bool `json:"-" toml:"-"`
Text string `json:"-" toml:"-"` Text string `json:"-" toml:"-"`
env runtime.Environment env runtime.Environment
@ -205,8 +204,8 @@ func (segment *Segment) writerCacheKey() string {
return fmt.Sprintf("segment_cache_writer_%s_%s", segment.Name(), segment.env.Pwd()) return fmt.Sprintf("segment_cache_writer_%s_%s", segment.Name(), segment.env.Pwd())
} }
func (segment *Segment) setText() { func (segment *Segment) SetText() {
if !segment.Enabled || len(segment.Text) != 0 { if !segment.Enabled {
return return
} }

View file

@ -323,6 +323,8 @@ func (e *Engine) filterSegments(block *config.Block) {
segments := make([]*config.Segment, 0) segments := make([]*config.Segment, 0)
for _, segment := range block.Segments { for _, segment := range block.Segments {
segment.SetText()
if !segment.Enabled && segment.ResolveStyle() != config.Accordion { if !segment.Enabled && segment.ResolveStyle() != config.Accordion {
continue continue
} }