Skip to content

Commit 4d04bef

Browse files
committed
fix: ensure the previousPartInstnace is cleaned up when belonging to a Rundown being removed from the playlist
1 parent ce586bc commit 4d04bef

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

packages/job-worker/src/ingest/commit.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ export async function updatePlayoutAfterChangingRundownInPlaylist(
576576
context: JobContext,
577577
playlist: DBRundownPlaylist,
578578
playlistLock: PlaylistLock,
579-
insertedRundown: ReadonlyDeep<DBRundown> | null
579+
insertedRundown: ReadonlyDeep<DBRundown> | null,
580+
rundownIdToForget: RundownId | null
580581
): Promise<void> {
581582
// ensure the 'old' playout is updated to remove any references to the rundown
582583
await runWithPlayoutModel(context, playlist, playlistLock, null, async (playoutModel) => {
@@ -591,6 +592,16 @@ export async function updatePlayoutAfterChangingRundownInPlaylist(
591592
return
592593
}
593594

595+
// Ensure previousPartInstance doesn't reference the old Rundown
596+
// The current and next partInstances are enforced by allowedToMoveRundownOutOfPlaylist
597+
if (
598+
rundownIdToForget &&
599+
playoutModel.previousPartInstance &&
600+
playoutModel.previousPartInstance.partInstance.rundownId === rundownIdToForget
601+
) {
602+
playoutModel.clearPreviousPartInstance()
603+
}
604+
594605
// Ensure playout is in sync
595606

596607
if (insertedRundown) {
@@ -711,7 +722,7 @@ export async function removeRundownFromPlaylistAndUpdatePlaylist(
711722

712723
if (updatedPlaylist) {
713724
// ensure the 'old' playout is updated to remove any references to the rundown
714-
await updatePlayoutAfterChangingRundownInPlaylist(context, updatedPlaylist, playlistLock, null)
725+
await updatePlayoutAfterChangingRundownInPlaylist(context, updatedPlaylist, playlistLock, null, rundownId)
715726
}
716727
}
717728

packages/job-worker/src/playout/model/PlayoutModel.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ export interface PlayoutModel extends PlayoutModelReadonly, StudioPlayoutModelBa
225225
*/
226226
clearSelectedPartInstances(): void
227227

228+
/**
229+
* Clear the currently selected previousPartInstance.
230+
* This can be useful if it references a Rundown that has been removed from the Playlist
231+
*/
232+
clearPreviousPartInstance(): void
233+
228234
/**
229235
* Insert an adlibbed PartInstance into the RundownPlaylist
230236
* @param part Part to insert

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,15 @@ export class PlayoutModelImpl extends PlayoutModelReadonlyImpl implements Playou
346346
this.#playlistHasChanged = true
347347
}
348348

349+
clearPreviousPartInstance(): void {
350+
this.playlistImpl.previousPartInfo = null
351+
352+
// Make sure that a hold isn't running. We can't block it here, so abort it immediately instead
353+
this.playlistImpl.holdState = RundownHoldState.NONE
354+
355+
this.#playlistHasChanged = true
356+
}
357+
349358
calculatePartTimings(
350359
fromPartInstance: PlayoutPartInstanceModel | null,
351360
toPartInstance: PlayoutPartInstanceModel,

packages/job-worker/src/rundownPlaylists.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,13 @@ export async function handleMoveRundownIntoPlaylist(
490490
}
491491

492492
// If the playlist is active this could have changed lookahead
493-
await updatePlayoutAfterChangingRundownInPlaylist(context, newPlaylist, intoPlaylistLock, rundown)
493+
await updatePlayoutAfterChangingRundownInPlaylist(
494+
context,
495+
newPlaylist,
496+
intoPlaylistLock,
497+
rundown,
498+
null
499+
)
494500
}
495501
)
496502
} else {
@@ -540,7 +546,7 @@ export async function handleRestoreRundownsInPlaylistToDefaultOrder(
540546

541547
if (updatedPlaylist) {
542548
// If the playlist is active this could have changed lookahead
543-
await updatePlayoutAfterChangingRundownInPlaylist(context, updatedPlaylist, playlistLock, null)
549+
await updatePlayoutAfterChangingRundownInPlaylist(context, updatedPlaylist, playlistLock, null, null)
544550
}
545551
}
546552
})

0 commit comments

Comments
 (0)