Skip to content

Commit 7723b78

Browse files
committed
fix:
1 parent 5067d60 commit 7723b78

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

meteor/server/publications/ingestStatus/publication.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PeripheralDeviceId, RundownId, RundownPlaylistId } from '@sofie-automation/corelib/dist/dataModel/Ids'
1+
import { PartId, PeripheralDeviceId, RundownId, RundownPlaylistId } from '@sofie-automation/corelib/dist/dataModel/Ids'
22
import { ReadonlyDeep } from 'type-fest'
33
import {
44
CustomPublishCollection,
@@ -8,7 +8,7 @@ import {
88
TriggerUpdate,
99
} from '../../lib/customPublication'
1010
import { logger } from '../../logging'
11-
import { ContentCache, createReactiveContentCache } from './reactiveContentCache'
11+
import { ContentCache, createReactiveContentCache, PartInstanceFields } from './reactiveContentCache'
1212
import { RundownsObserver } from '../lib/rundownsObserver'
1313
import { RundownContentObserver } from './rundownContentObserver'
1414
import {
@@ -22,6 +22,7 @@ import { protectString } from '@sofie-automation/corelib/dist/protectedString'
2222
import { DBRundown } from '@sofie-automation/corelib/dist/dataModel/Rundown'
2323
import { NrcsIngestCacheType } from '@sofie-automation/corelib/dist/dataModel/NrcsIngestDataCache'
2424
import _ from 'underscore'
25+
import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
2526

2627
interface IngestRundownStatusArgs {
2728
readonly deviceId: PeripheralDeviceId
@@ -193,6 +194,28 @@ function regenerateForRundown(cache: ReadonlyDeep<ContentCache>, rundownId: Rund
193194
newDoc.active = playlist.rehearsal ? 'rehearsal' : 'active'
194195
}
195196

197+
// Find the most important part instance for each part
198+
const partInstanceMap = new Map<PartId, Pick<DBPartInstance, PartInstanceFields>>()
199+
if (playlist) {
200+
for (const partInstance of cache.PartInstances.find({}).fetch()) {
201+
if (partInstance.rundownId !== rundownId) continue
202+
// Ignore the next partinstance
203+
if (partInstance._id === playlist.nextPartInfo?.partInstanceId) continue
204+
205+
// The current part instance is the most important
206+
if (partInstance._id === playlist.currentPartInfo?.partInstanceId) {
207+
partInstanceMap.set(partInstance.part._id, partInstance)
208+
continue
209+
}
210+
211+
// Take the part with the highest takeCount
212+
const existingEntry = partInstanceMap.get(partInstance.part._id)
213+
if (!existingEntry || existingEntry.takeCount < partInstance.takeCount) {
214+
partInstanceMap.set(partInstance.part._id, partInstance)
215+
}
216+
}
217+
}
218+
196219
const nrcsSegments = cache.NrcsIngestData.find({ rundownId, type: NrcsIngestCacheType.SEGMENT }).fetch()
197220
for (const nrcsSegment of nrcsSegments) {
198221
const nrcsParts = cache.NrcsIngestData.find({
@@ -207,16 +230,8 @@ function regenerateForRundown(cache: ReadonlyDeep<ContentCache>, rundownId: Rund
207230
nrcsParts.map((nrcsPart) => {
208231
if (!nrcsPart.partId || !nrcsPart.segmentId) return null
209232

210-
const part = cache.Parts.findOne({ rundownId, _id: nrcsPart.partId })
211-
const partInstance = cache.PartInstances.findOne({
212-
rundownId,
213-
// segmentId: nrcsPart.segmentId, // nocommit - these don't match for some reason
214-
'part._id': nrcsPart.partId,
215-
// nocommit TODO - prefer the currentPartInstance
216-
_id: {
217-
$not: playlist?.nextPartInfo?.partInstanceId ?? protectString(''),
218-
},
219-
})
233+
const part = cache.Parts.findOne({ _id: nrcsPart.partId, rundownId })
234+
const partInstance = partInstanceMap.get(nrcsPart.partId)
220235

221236
// Determine the playback status from the PartInstance
222237
let playbackStatus = IngestPartPlaybackStatus.UNKNOWN

meteor/server/publications/ingestStatus/reactiveContentCache.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ export const partFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<Pick<DBP
4040
ingestNotifyPartReady: 1,
4141
})
4242

43-
export type PartInstanceFields = '_id' | 'rundownId' | 'segmentId' | 'part'
43+
export type PartInstanceFields = '_id' | 'rundownId' | 'segmentId' | 'part' | 'takeCount'
4444
export const partInstanceFieldSpecifier = literal<
4545
MongoFieldSpecifierOnesStrict<Pick<PartInstance, PartInstanceFields>>
4646
>({
4747
_id: 1,
4848
rundownId: 1,
4949
segmentId: 1,
5050
part: 1, // This could be more granular, but it should be pretty stable
51+
takeCount: 1,
5152
})
5253

5354
export interface ContentCache {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@ import { DatabasePersistedModel } from '../../../modelBase'
5656
import { ExpectedPackageDBFromStudioBaselineObjects } from '@sofie-automation/corelib/dist/dataModel/ExpectedPackages'
5757
import { ExpectedPlayoutItemStudio } from '@sofie-automation/corelib/dist/dataModel/ExpectedPlayoutItem'
5858
import { StudioBaselineHelper } from '../../../studio/model/StudioBaselineHelper'
59-
import { EventsJobs } from '@sofie-automation/corelib/dist/worker/events'
6059
import { QuickLoopService } from '../services/QuickLoopService'
6160
import { calculatePartTimings, PartCalculatedTimings } from '@sofie-automation/corelib/dist/playout/timings'
6261
import { PieceInstanceWithTimings } from '@sofie-automation/corelib/dist/playout/processAndPrune'
63-
import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyError'
6462
import { NotificationsModelHelper } from '../../../notifications/NotificationsModelHelper'
6563

6664
export class PlayoutModelReadonlyImpl implements PlayoutModelReadonly {
@@ -519,7 +517,6 @@ export class PlayoutModelImpl extends PlayoutModelReadonlyImpl implements Playou
519517
this.#pendingPartInstanceTimingEvents.add(partInstanceId)
520518
}
521519

522-
523520
removeAllRehearsalPartInstances(): void {
524521
const partInstancesToRemove: PartInstanceId[] = []
525522

@@ -681,8 +678,6 @@ export class PlayoutModelImpl extends PlayoutModelReadonlyImpl implements Playou
681678
}
682679
this.#pendingPartInstanceTimingEvents.clear()
683680

684-
685-
686681
if (span) span.end()
687682
}
688683

packages/job-worker/src/playout/take.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ export function updatePartInstanceOnTake(
539539
export async function afterTake(
540540
context: JobContext,
541541
playoutModel: PlayoutModel,
542-
takePartInstance: PlayoutPartInstanceModel
542+
_takePartInstance: PlayoutPartInstanceModel
543543
): Promise<void> {
544544
const span = context.startSpan('afterTake')
545545
// This function should be called at the end of a "take" event (when the Parts have been updated)

packages/mos-gateway/src/mosHandler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
MosConnection,
3-
IMOSDevice,
43
IMOSConnectionStatus,
54
IMOSRunningOrder,
65
IMOSROAck,
@@ -41,7 +40,7 @@ import { PeripheralDeviceForDevice } from '@sofie-automation/server-core-integra
4140
import _ = require('underscore')
4241
import { MosStatusHandler } from './mosStatusHandler'
4342

44-
interface MosConfig {
43+
export interface MosConfig {
4544
self: IConnectionConfig
4645
// devices: Array<IMOSDeviceConnectionOptions>
4746
}

0 commit comments

Comments
 (0)