Skip to content

Commit c7ec12e

Browse files
committed
wip: first round of types
1 parent 615cd1e commit c7ec12e

File tree

7 files changed

+58
-12
lines changed

7 files changed

+58
-12
lines changed

meteor/server/api/__tests__/cleanup.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ async function setDefaultDatatoDB(env: DefaultEnvironment, now: number) {
261261
bucketId: null,
262262
created: 0,
263263
package: {} as any,
264-
ingestSources: [] as any,
264+
ingestSources: [],
265+
playoutSources: {
266+
pieceInstanceIds: [],
267+
},
265268
})
266269
await ExpectedPackageWorkStatuses.insertAsync({
267270
_id: getRandomId(),

meteor/server/migration/X_X_X.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ export const addSteps = addMigrationSteps(CURRENT_SYSTEM_VERSION, [
142142
},
143143
created: pkg.created,
144144
ingestSources: [ingestSource],
145+
playoutSources: {
146+
pieceInstanceIds: [],
147+
},
145148
} satisfies Complete<ExpectedPackageDB>)
146149
}
147150
}

packages/corelib/src/dataModel/ExpectedPackages.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ export interface ExpectedPackageDB {
5858
*/
5959
ingestSources: ExpectedPackageIngestSource[]
6060

61-
// playoutSources: {
62-
// /** Any playout PieceInstance. This is limited to the current and next partInstances */
63-
// pieceInstanceIds: PieceInstanceId[]
64-
// }
61+
playoutSources: {
62+
/** Any playout PieceInstance. This is limited to the current and next partInstances */ // nocommit - confirm this claim
63+
pieceInstanceIds: PieceInstanceId[]
64+
}
6565
}
6666

6767
export interface ExpectedPackageIngestSourceBase {
@@ -173,3 +173,7 @@ export function getExpectedPackageIdNew(
173173

174174
return protectString(`${parentId}_${getHash(objHash)}`)
175175
}
176+
177+
export function isPackageReferencedByPlayout(expectedPackage: Pick<ExpectedPackageDB, 'playoutSources'>): boolean {
178+
return expectedPackage.playoutSources.pieceInstanceIds.length > 0
179+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ function generateBucketExpectedPackages<TSource = never>(
109109
listenToPackageInfoUpdates: expectedPackage.listenToPackageInfoUpdates,
110110
},
111111
],
112+
playoutSources: {
113+
// These don't belong to a rundown, so can't be referenced by playout
114+
pieceInstanceIds: [],
115+
},
112116
})
113117
}
114118

packages/job-worker/src/ingest/model/implementation/SaveIngestModel.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { AdLibAction } from '@sofie-automation/corelib/dist/dataModel/AdlibAction'
22
import { AdLibPiece } from '@sofie-automation/corelib/dist/dataModel/AdLibPiece'
33
import { ExpectedMediaItem } from '@sofie-automation/corelib/dist/dataModel/ExpectedMediaItem'
4-
import { ExpectedPackageDB, ExpectedPackageDBType } from '@sofie-automation/corelib/dist/dataModel/ExpectedPackages'
4+
import {
5+
ExpectedPackageDB,
6+
ExpectedPackageDBType,
7+
isPackageReferencedByPlayout,
8+
} from '@sofie-automation/corelib/dist/dataModel/ExpectedPackages'
59
import { ExpectedPlayoutItem } from '@sofie-automation/corelib/dist/dataModel/ExpectedPlayoutItem'
610
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
711
import { Piece } from '@sofie-automation/corelib/dist/dataModel/Piece'
@@ -110,13 +114,13 @@ async function writeExpectedPackagesChangesForRundown(
110114
{
111115
projection: {
112116
_id: 1,
113-
// Future: playoutSources
117+
playoutSources: 1, // nocommit - can this be made just a count?
114118
},
115119
}
116-
)) as Pick<ExpectedPackageDB, '_id' | 'created'>[]
120+
)) as Pick<ExpectedPackageDB, '_id' | 'created' | 'playoutSources'>[]
117121
const existingDocsMap = normalizeArrayToMap(existingDocs, '_id')
118122

119-
const packagesToSave = new Map<ExpectedPackageId, ExpectedPackageDB>()
123+
const packagesToSave = new Map<ExpectedPackageId, Omit<ExpectedPackageDB, 'playoutSources'>>()
120124
for (const doc of documentsToSave) {
121125
const partialDoc = packagesToSave.get(doc.packageId)
122126

@@ -148,7 +152,12 @@ async function writeExpectedPackagesChangesForRundown(
148152
// Insert this new document
149153
ops.push({
150154
insertOne: {
151-
document: doc,
155+
document: {
156+
...doc,
157+
playoutSources: {
158+
pieceInstanceIds: [],
159+
},
160+
},
152161
},
153162
})
154163
} else {
@@ -170,13 +179,17 @@ async function writeExpectedPackagesChangesForRundown(
170179

171180
// Look over the existing documents, and see is no longer referenced
172181
const idsToDelete: ExpectedPackageId[] = []
182+
const idsToClearSources: ExpectedPackageId[] = []
173183

174184
for (const doc of existingDocs) {
175185
// Skip if this document is in the list of documents to save
176186
if (packagesToSave.has(doc._id)) continue
177187

178-
// Future: check for playoutSources
179-
idsToDelete.push(doc._id)
188+
if (isPackageReferencedByPlayout(doc)) {
189+
idsToClearSources.push(doc._id)
190+
} else {
191+
idsToDelete.push(doc._id)
192+
}
180193
}
181194

182195
if (idsToDelete.length > 0) {
@@ -186,6 +199,18 @@ async function writeExpectedPackagesChangesForRundown(
186199
},
187200
})
188201
}
202+
if (idsToClearSources.length > 0) {
203+
ops.push({
204+
updateMany: {
205+
filter: { _id: { $in: idsToClearSources as any } },
206+
update: {
207+
$set: {
208+
ingestSources: [],
209+
},
210+
},
211+
},
212+
})
213+
}
189214

190215
if (ops.length > 0) await context.directCollections.ExpectedPackages.bulkWrite(ops)
191216
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,9 @@ export async function handleRestorePlaylistSnapshot(
467467
},
468468

469469
ingestSources: [source],
470+
playoutSources: {
471+
pieceInstanceIds: [],
472+
},
470473
}
471474

472475
expectedPackageIdMap.set(expectedPackage._id, newExpectedPackage._id)

packages/job-worker/src/studio/model/StudioBaselineHelper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export class StudioBaselineHelper {
8585
created: Date.now(),
8686
package: pkg.package,
8787
ingestSources: [pkg.source],
88+
playoutSources: {
89+
// This doesn't belong to a rundown, so can't be referenced by playout
90+
pieceInstanceIds: [],
91+
},
8892
} satisfies Complete<ExpectedPackageDB>)
8993
),
9094
{

0 commit comments

Comments
 (0)