From 69402ea2e41e666d47e39b4ae95710c2002744ad Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Fri, 20 Feb 2026 17:06:43 -0700 Subject: [PATCH] Switch Show to pointer slices, share objects between Show and Timeline --- cmd/qrunproxy/main.go | 8 ++++---- cmd/qrunproxy/timeline.go | 31 +++++++++++++++---------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/cmd/qrunproxy/main.go b/cmd/qrunproxy/main.go index 428a68d..7fa603b 100644 --- a/cmd/qrunproxy/main.go +++ b/cmd/qrunproxy/main.go @@ -102,16 +102,16 @@ func main() { } } -func loadMockShow() (Show, error) { +func loadMockShow() (*Show, error) { buf, err := staticFS.ReadFile("static/show.json") if err != nil { - return Show{}, err + return nil, err } var show Show if err := json.Unmarshal(buf, &show); err != nil { - return Show{}, err + return nil, err } - return show, nil + return &show, nil } func writeJSON(w http.ResponseWriter, v any) { diff --git a/cmd/qrunproxy/timeline.go b/cmd/qrunproxy/timeline.go index 62da1c8..000fd16 100644 --- a/cmd/qrunproxy/timeline.go +++ b/cmd/qrunproxy/timeline.go @@ -7,9 +7,9 @@ const ( ) type Show struct { - Tracks []Track `json:"tracks"` - Blocks []Block `json:"blocks"` - Triggers []Trigger `json:"triggers"` + Tracks []*Track `json:"tracks"` + Blocks []*Block `json:"blocks"` + Triggers []*Trigger `json:"triggers"` } type Track struct { @@ -41,15 +41,15 @@ type TriggerTarget struct { } type TimelineTrack struct { - Track + *Track Cells []*TimelineCell `json:"cells"` } type Timeline struct { - Tracks []*TimelineTrack `json:"tracks"` - Blocks map[string]Block `json:"blocks"` + Tracks []*TimelineTrack `json:"tracks"` + Blocks map[string]*Block `json:"blocks"` - show Show `json:"-"` + show *Show `json:"-"` trackIdx map[string]*TimelineTrack `json:"-"` constraints []constraint `json:"-"` exclusives []exclusiveGroup `json:"-"` @@ -78,7 +78,7 @@ type exclusiveGroup struct { members []*TimelineCell } -func validateShow(show Show) error { +func validateShow(show *Show) error { startTargeted := map[string]bool{} for _, trigger := range show.Triggers { for _, target := range trigger.Targets { @@ -100,18 +100,18 @@ func validateShow(show Show) error { return nil } -func BuildTimeline(show Show) (Timeline, error) { +func BuildTimeline(show *Show) (Timeline, error) { if err := validateShow(show); err != nil { return Timeline{}, err } tl := Timeline{ show: show, - Blocks: map[string]Block{}, + Blocks: map[string]*Block{}, trackIdx: map[string]*TimelineTrack{}, } - cueTrack := &TimelineTrack{Track: Track{ID: cueTrackID, Name: "Cue"}} + cueTrack := &TimelineTrack{Track: &Track{ID: cueTrackID, Name: "Cue"}} tl.Tracks = append(tl.Tracks, cueTrack) tl.trackIdx[cueTrackID] = cueTrack for _, track := range show.Tracks { @@ -158,7 +158,7 @@ func (track *TimelineTrack) appendCells(cells ...*TimelineCell) { } } -func getCueCells(block Block) []*TimelineCell { +func getCueCells(block *Block) []*TimelineCell { return []*TimelineCell{{ BlockID: block.ID, IsStart: true, @@ -167,7 +167,7 @@ func getCueCells(block Block) []*TimelineCell { }} } -func getBlockCells(block Block) []*TimelineCell { +func getBlockCells(block *Block) []*TimelineCell { return []*TimelineCell{ {BlockID: block.ID, IsStart: true, Event: "START"}, {BlockID: block.ID, IsTitle: true}, @@ -187,9 +187,8 @@ func (tl *Timeline) findCell(blockID, event string) *TimelineCell { } func (tl *Timeline) buildCells(endChains map[string]bool) { - for _, sb := range tl.show.Blocks { - block := tl.Blocks[sb.ID] - track := tl.trackIdx[block.Track] + for _, block := range tl.show.Blocks { + track := tl.trackIdx[tl.Blocks[block.ID].Track] var cells []*TimelineCell switch block.Type { case "cue":