@@ -178,8 +178,6 @@ export async function writeExpectedPackagesForPlayoutSources(
178178 ) ) as Pick < ExpectedPackageDB , '_id' | 'playoutSources' > [ ]
179179 const existingPackagesMap = normalizeArrayToMap ( existingPackages , '_id' )
180180
181- // const targetPackages = new Map<ExpectedPackageId, ExpectedPackageEntry>()
182-
183181 const pieceInstancesToAddToPackages = new Map < ExpectedPackageId , PieceInstanceId [ ] > ( )
184182 const packagesToInsert = new Map < ExpectedPackageId , ExpectedPackageEntry > ( )
185183
@@ -203,12 +201,14 @@ export async function writeExpectedPackagesForPlayoutSources(
203201 pieceInstanceIds . push ( pieceInstance . pieceInstance . _id )
204202 pieceInstancesToAddToPackages . set ( packageId , pieceInstanceIds )
205203 } else {
206- // Record as needing a new package
204+ // Record as needing a new document
207205 packagesToInsert . set ( packageId , {
208206 _id : packageId ,
209207 package : expectedPackage ,
210208 pieceInstanceIds : [ pieceInstance . pieceInstance . _id ] ,
211209 } )
210+
211+ // Future: If this came from a bucket, can we copy the packageInfos across to minimise latency until the status is ready?
212212 }
213213 }
214214 }
@@ -256,18 +256,15 @@ export async function writeExpectedPackagesForPlayoutSources(
256256 }
257257
258258 // We can't easily track any references which have been deleted, so we should schedule a cleanup job to deal with that for us
259- await context . queueStudioJob ( StudioJobs . CleanupOrphanedExpectedPackageReferences , {
260- playlistId : playlistId ,
261- rundownId : rundownId ,
262- } )
263-
264- // TODO: Implement this function
265- /**
266- * Here we have access to all the PieceInstances for any 'current' partinstances (within the current segment?, and whatever is nexted)
267- * So we can easily iterate through them all to build out the needed expected packages.
268- * From there, we can make sure that they are referenced in the database.
269- *
270- * We can't track any references which have been deleted, so we probably want to dispatch a job to perform the cleanup on a debounce.
271- * Timing isnt critical, as this will be stale and unreferenced data (other than it could cause package-manager to do pointless work)
272- */
259+ await context . queueStudioJob (
260+ StudioJobs . CleanupOrphanedExpectedPackageReferences ,
261+ {
262+ playlistId : playlistId ,
263+ rundownId : rundownId ,
264+ } ,
265+ {
266+ lowPriority : true ,
267+ debounce : 1000 ,
268+ }
269+ )
273270}
0 commit comments