Skip to content

Commit 82ba095

Browse files
committed
fix(LoadPlayoutModel): rundowns are not sorted in order, which can cause unusual effects
1 parent 5bc0155 commit 82ba095

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/corelib/src/playout/playlist.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DBRundown } from '../dataModel/Rundown'
12
import { DBSegment } from '../dataModel/Segment'
23
import { DBPart } from '../dataModel/Part'
34
import { DBPartInstance } from '../dataModel/PartInstance'
@@ -89,3 +90,22 @@ export function sortRundownIDsInPlaylist(
8990

9091
return [...sortedVerifiedExisting, ...missingIds]
9192
}
93+
94+
export function sortRundownsWithinPlaylist(
95+
sortedPossibleIds: ReadonlyDeep<RundownId[]>,
96+
unsortedRundowns: DBRundown[]
97+
): DBRundown[] {
98+
return unsortedRundowns.slice().sort((a, b) => {
99+
const indexA = sortedPossibleIds.indexOf(a._id)
100+
const indexB = sortedPossibleIds.indexOf(b._id)
101+
if (indexA === -1 && indexB === -1) {
102+
return a._id.toString().localeCompare(b._id.toString())
103+
} else if (indexA === -1) {
104+
return -1
105+
} else if (indexB === -1) {
106+
return 1
107+
}
108+
109+
return indexA - indexB
110+
})
111+
}

packages/job-worker/src/playout/model/implementation/LoadPlayoutModel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { PeripheralDevice } from '@sofie-automation/corelib/dist/dataModel/Perip
2222
import { PlayoutModel, PlayoutModelPreInit } from '../PlayoutModel'
2323
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
2424
import { RundownBaselineObj } from '@sofie-automation/corelib/dist/dataModel/RundownBaselineObj'
25+
import { sortRundownsWithinPlaylist } from '@sofie-automation/corelib/dist/playout/playlist'
2526

2627
/**
2728
* Load a PlayoutModelPreInit for the given RundownPlaylist
@@ -59,7 +60,7 @@ export async function loadPlayoutModelPreInit(
5960
peripheralDevices: PeripheralDevices,
6061

6162
playlist: Playlist,
62-
rundowns: Rundowns,
63+
rundowns: sortRundownsWithinPlaylist(Playlist.rundownIdsInOrder, Rundowns),
6364

6465
getRundown: (id: RundownId) => Rundowns.find((rd) => rd._id === id),
6566
}

0 commit comments

Comments
 (0)