Skip to content

Commit ba987d5

Browse files
committed
fix: limit scope of loading of NrcsIngestData for ingestDeviceRundownStatus publication
1 parent ec8f562 commit ba987d5

File tree

3 files changed

+55
-37
lines changed

3 files changed

+55
-37
lines changed

meteor/server/publications/ingestStatus/createIngestRundownStatus.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ import {
99
} from '@sofie-automation/shared-lib/dist/ingest/rundownStatus'
1010
import type { ReadonlyDeep } from 'type-fest'
1111
import _ from 'underscore'
12-
import type { ContentCache, PartFields, PartInstanceFields, PlaylistFields } from './reactiveContentCache'
13-
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
12+
import type { ContentCache, PartCompact, PartInstanceCompact, PlaylistCompact } from './reactiveContentCache'
1413
import { ReactiveCacheCollection } from '../lib/ReactiveCacheCollection'
15-
import { PartInstance } from '@sofie-automation/meteor-lib/dist/collections/PartInstances'
16-
import { IngestPart } from '@sofie-automation/blueprints-integration'
17-
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
1814
import { unprotectString } from '@sofie-automation/corelib/dist/protectedString'
1915

2016
export function createIngestRundownStatus(
@@ -75,7 +71,7 @@ export function createIngestRundownStatus(
7571
nrcsPart.data.externalId
7672
)
7773

78-
return createIngestPartStatus(playlist, partInstances, parts, nrcsPart.data as IngestPart)
74+
return createIngestPartStatus(playlist, partInstances, parts, nrcsPart.data.externalId)
7975
})
8076
),
8177
})
@@ -85,12 +81,12 @@ export function createIngestRundownStatus(
8581
}
8682

8783
function findPartInstancesForIngestPart(
88-
playlist: Pick<DBRundownPlaylist, PlaylistFields> | undefined,
84+
playlist: PlaylistCompact | undefined,
8985
rundownId: RundownId,
90-
partInstancesCache: ReadonlyDeep<ReactiveCacheCollection<Pick<PartInstance, PartInstanceFields>>>,
86+
partInstancesCache: ReadonlyDeep<ReactiveCacheCollection<PartInstanceCompact>>,
9187
partExternalId: string
9288
) {
93-
const result: Record<string, Pick<PartInstance, PartInstanceFields>> = {}
89+
const result: Record<string, PartInstanceCompact> = {}
9490
if (!playlist) return result
9591

9692
const candidatePartInstances = partInstancesCache
@@ -132,10 +128,10 @@ function findPartInstancesForIngestPart(
132128
}
133129

134130
function createIngestPartStatus(
135-
playlist: Pick<DBRundownPlaylist, PlaylistFields> | undefined,
136-
partInstances: Record<string, Pick<PartInstance, PartInstanceFields>>,
137-
parts: Pick<DBPart, PartFields>[],
138-
ingestPart: IngestPart
131+
playlist: PlaylistCompact | undefined,
132+
partInstances: Record<string, PartInstanceCompact>,
133+
parts: PartCompact[],
134+
ingestPartExternalId: string
139135
): IngestPartStatus {
140136
// Determine the playback status from the PartInstance
141137
let playbackStatus = IngestPartPlaybackStatus.UNKNOWN
@@ -144,7 +140,7 @@ function createIngestPartStatus(
144140

145141
const itemsReady: IngestPartNotifyItemReady[] = []
146142

147-
const updateStatusWithPart = (part: Pick<DBPart, PartFields>) => {
143+
const updateStatusWithPart = (part: PartCompact) => {
148144
// If the part affects the ready status, update it
149145
if (typeof part.ingestNotifyPartReady === 'boolean') {
150146
isReady = (isReady ?? true) && part.ingestNotifyPartReady
@@ -158,7 +154,7 @@ function createIngestPartStatus(
158154

159155
// Loop through the partInstances, starting off the state
160156
if (playlist) {
161-
for (const partInstance of Object.values<Pick<PartInstance, PartInstanceFields>>(partInstances)) {
157+
for (const partInstance of Object.values<PartInstanceCompact>(partInstances)) {
162158
if (!partInstance) continue
163159

164160
if (partInstance.part.shouldNotifyCurrentPlayingPart) {
@@ -185,7 +181,7 @@ function createIngestPartStatus(
185181
}
186182

187183
return {
188-
externalId: ingestPart.externalId,
184+
externalId: ingestPartExternalId,
189185

190186
isReady: isReady,
191187
itemsReady: itemsReady,

meteor/server/publications/ingestStatus/reactiveContentCache.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@ import type { RundownId } from '@sofie-automation/corelib/dist/dataModel/Ids'
88
import type { DBRundown } from '@sofie-automation/corelib/dist/dataModel/Rundown'
99
import type { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
1010

11-
export type PlaylistFields = '_id' | 'activationId' | 'rehearsal' | 'currentPartInfo' | 'nextPartInfo'
12-
export const playlistFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<Pick<DBRundownPlaylist, PlaylistFields>>>({
11+
export type PlaylistCompact = Pick<
12+
DBRundownPlaylist,
13+
'_id' | 'activationId' | 'rehearsal' | 'currentPartInfo' | 'nextPartInfo'
14+
>
15+
export const playlistFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<PlaylistCompact>>({
1316
_id: 1,
1417
activationId: 1,
1518
rehearsal: 1,
1619
currentPartInfo: 1,
1720
nextPartInfo: 1,
1821
})
1922

20-
export type RundownFields = '_id' | 'externalId' | 'playlistId'
21-
export const rundownFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<Pick<DBRundown, RundownFields>>>({
23+
export type RundownCompact = Pick<DBRundown, '_id' | 'externalId' | 'playlistId'>
24+
export const rundownFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<RundownCompact>>({
2225
_id: 1,
2326
externalId: 1,
2427
playlistId: 1,
2528
})
2629

27-
export type PartFields =
30+
export type PartCompact = Pick<
31+
DBPart,
2832
| '_id'
2933
| 'rundownId'
3034
| 'segmentId'
@@ -33,7 +37,8 @@ export type PartFields =
3337
| 'ingestNotifyPartReady'
3438
| 'ingestNotifyItemsReady'
3539
| 'ingestNotifyPartExternalId'
36-
export const partFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<Pick<DBPart, PartFields>>>({
40+
>
41+
export const partFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<PartCompact>>({
3742
_id: 1,
3843
rundownId: 1,
3944
segmentId: 1,
@@ -44,36 +49,50 @@ export const partFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<Pick<DBP
4449
ingestNotifyPartExternalId: 1,
4550
})
4651

47-
export type PartInstanceFields = '_id' | 'rundownId' | 'segmentId' | 'part' | 'takeCount'
48-
export const partInstanceFieldSpecifier = literal<
49-
MongoFieldSpecifierOnesStrict<Pick<PartInstance, PartInstanceFields>>
50-
>({
52+
export type PartInstanceCompact = Pick<PartInstance, '_id' | 'rundownId' | 'segmentId' | 'part' | 'takeCount'>
53+
export const partInstanceFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<PartInstanceCompact>>({
5154
_id: 1,
5255
rundownId: 1,
5356
segmentId: 1,
5457
part: 1, // This could be more granular, but it should be pretty stable
5558
takeCount: 1,
5659
})
5760

61+
export type NrcsIngestDataCacheObjCompact = Pick<
62+
NrcsIngestDataCacheObj,
63+
'_id' | 'type' | 'rundownId' | 'segmentId' | 'partId'
64+
> & { data: { externalId: string } }
65+
export const nrcsIngestDataCacheObjSpecifier = literal<MongoFieldSpecifierOnesStrict<NrcsIngestDataCacheObjCompact>>({
66+
_id: 1,
67+
type: 1,
68+
rundownId: 1,
69+
segmentId: 1,
70+
partId: 1,
71+
data: {
72+
// We need to be very selective here, as the payload portion could contain data not safe for minimongo
73+
externalId: 1,
74+
},
75+
})
76+
5877
export interface ContentCache {
5978
RundownIds: RundownId[]
6079

61-
Playlists: ReactiveCacheCollection<Pick<DBRundownPlaylist, PlaylistFields>>
62-
Rundowns: ReactiveCacheCollection<Pick<DBRundown, RundownFields>>
63-
NrcsIngestData: ReactiveCacheCollection<NrcsIngestDataCacheObj>
64-
Parts: ReactiveCacheCollection<Pick<DBPart, PartFields>>
65-
PartInstances: ReactiveCacheCollection<Pick<PartInstance, PartInstanceFields>>
80+
Playlists: ReactiveCacheCollection<PlaylistCompact>
81+
Rundowns: ReactiveCacheCollection<RundownCompact>
82+
NrcsIngestData: ReactiveCacheCollection<NrcsIngestDataCacheObjCompact>
83+
Parts: ReactiveCacheCollection<PartCompact>
84+
PartInstances: ReactiveCacheCollection<PartInstanceCompact>
6685
}
6786

6887
export function createReactiveContentCache(rundownIds: RundownId[]): ContentCache {
6988
const cache: ContentCache = {
7089
RundownIds: rundownIds,
7190

72-
Playlists: new ReactiveCacheCollection<Pick<DBRundownPlaylist, PlaylistFields>>('playlists'),
73-
Rundowns: new ReactiveCacheCollection<Pick<DBRundown, RundownFields>>('rundowns'),
74-
NrcsIngestData: new ReactiveCacheCollection<NrcsIngestDataCacheObj>('nrcsIngestData'), // TODO - is this needed?
75-
Parts: new ReactiveCacheCollection<Pick<DBPart, PartFields>>('parts'),
76-
PartInstances: new ReactiveCacheCollection<Pick<PartInstance, PartInstanceFields>>('partInstances'),
91+
Playlists: new ReactiveCacheCollection<PlaylistCompact>('playlists'),
92+
Rundowns: new ReactiveCacheCollection<RundownCompact>('rundowns'),
93+
NrcsIngestData: new ReactiveCacheCollection<NrcsIngestDataCacheObjCompact>('nrcsIngestData'),
94+
Parts: new ReactiveCacheCollection<PartCompact>('parts'),
95+
PartInstances: new ReactiveCacheCollection<PartInstanceCompact>('partInstances'),
7796
}
7897

7998
return cache

meteor/server/publications/ingestStatus/rundownContentObserver.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { RundownId, RundownPlaylistId } from '@sofie-automation/corelib/dist/dat
33
import { logger } from '../../logging'
44
import {
55
ContentCache,
6+
nrcsIngestDataCacheObjSpecifier,
67
partFieldSpecifier,
78
partInstanceFieldSpecifier,
89
playlistFieldSpecifier,
@@ -111,7 +112,9 @@ export class RundownContentObserver {
111112
},
112113
},
113114
cache.NrcsIngestData.link(),
114-
{},
115+
{
116+
projection: nrcsIngestDataCacheObjSpecifier,
117+
},
115118
{
116119
nonMutatingCallbacks: true,
117120
}

0 commit comments

Comments
 (0)