@@ -19,7 +19,8 @@ import { PieceInstance } from '@sofie-automation/corelib/dist/dataModel/PieceIns
1919import { Meteor } from 'meteor/meteor'
2020import { EmptyPieceTimelineObjectsBlob } from '@sofie-automation/corelib/dist/dataModel/Piece'
2121import {
22- IngestDataCacheObjId ,
22+ NrcsIngestDataCacheObjId ,
23+ SofieIngestDataCacheObjId ,
2324 PartId ,
2425 PeripheralDeviceId ,
2526 RundownId ,
@@ -42,7 +43,7 @@ import '../cronjobs'
4243import '../api/peripheralDevice'
4344import {
4445 CoreSystem ,
45- IngestDataCache ,
46+ NrcsIngestDataCache ,
4647 PartInstances ,
4748 Parts ,
4849 PeripheralDeviceCommands ,
@@ -51,8 +52,9 @@ import {
5152 Snapshots ,
5253 UserActionsLog ,
5354 Segments ,
55+ SofieIngestDataCache ,
5456} from '../collections'
55- import { IngestCacheType } from '@sofie-automation/corelib/dist/dataModel/IngestDataCache '
57+ import { NrcsIngestCacheType } from '@sofie-automation/corelib/dist/dataModel/NrcsIngestDataCache '
5658import { JSONBlobStringify } from '@sofie-automation/shared-lib/dist/lib/JSONBlob'
5759import {
5860 DefaultEnvironment ,
@@ -61,6 +63,7 @@ import {
6163} from '../../__mocks__/helpers/database'
6264import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
6365import { Settings } from '../Settings'
66+ import { SofieIngestCacheType } from '@sofie-automation/corelib/dist/dataModel/SofieIngestDataCache'
6467
6568describe ( 'cronjobs' , ( ) => {
6669 let env : DefaultEnvironment
@@ -170,45 +173,95 @@ describe('cronjobs', () => {
170173 await PeripheralDevices . removeAsync ( { } )
171174 } )
172175
173- testInFiber ( 'Remove IngestDataCache objects that are not connected to any Rundown' , async ( ) => {
174- // Set up a mock rundown, a detached IngestDataCache object and an object attached to the mock rundown
175- // Detached IngestDataCache object 0
176- const dataCache0Id = protectString < IngestDataCacheObjId > ( getRandomString ( ) )
177- await IngestDataCache . mutableCollection . insertAsync ( {
176+ testInFiber ( 'Remove NrcsIngestDataCache objects that are not connected to any Rundown' , async ( ) => {
177+ // Set up a mock rundown, a detached NrcsIngestDataCache object and an object attached to the mock rundown
178+ // Detached NrcsIngestDataCache object 0
179+ const dataCache0Id = protectString < NrcsIngestDataCacheObjId > ( getRandomString ( ) )
180+ await NrcsIngestDataCache . mutableCollection . insertAsync ( {
178181 _id : dataCache0Id ,
179182 data : {
180183 externalId : '' ,
181184 name : '' ,
182185 segments : [ ] ,
183186 type : '' ,
187+ rundownSource : { } as any ,
188+ payload : undefined ,
184189 } ,
185190 modified : new Date ( 2000 , 0 , 1 , 0 , 0 , 0 ) . getTime ( ) ,
186191 // this one is attached to rundown0
187192 rundownId : getRandomId ( ) ,
188- type : IngestCacheType . RUNDOWN ,
193+ type : NrcsIngestCacheType . RUNDOWN ,
189194 } )
190- // Attached IngestDataCache object 1
191- const dataCache1Id = protectString < IngestDataCacheObjId > ( getRandomString ( ) )
192- await IngestDataCache . mutableCollection . insertAsync ( {
195+ // Attached NrcsIngestDataCache object 1
196+ const dataCache1Id = protectString < NrcsIngestDataCacheObjId > ( getRandomString ( ) )
197+ await NrcsIngestDataCache . mutableCollection . insertAsync ( {
193198 _id : dataCache1Id ,
194199 data : {
195200 externalId : '' ,
196201 name : '' ,
197202 segments : [ ] ,
198203 type : '' ,
204+ rundownSource : { } as any ,
205+ payload : undefined ,
199206 } ,
200207 modified : new Date ( 2000 , 0 , 1 , 0 , 0 , 0 ) . getTime ( ) ,
201208 // just some random ID
202209 rundownId : rundownId ,
203- type : IngestCacheType . RUNDOWN ,
210+ type : NrcsIngestCacheType . RUNDOWN ,
204211 } )
205212
206213 await runCronjobs ( )
207214
208- expect ( await IngestDataCache . findOneAsync ( dataCache1Id ) ) . toMatchObject ( {
215+ expect ( await NrcsIngestDataCache . findOneAsync ( dataCache1Id ) ) . toMatchObject ( {
209216 _id : dataCache1Id ,
210217 } )
211- expect ( await IngestDataCache . findOneAsync ( dataCache0Id ) ) . toBeUndefined ( )
218+ expect ( await NrcsIngestDataCache . findOneAsync ( dataCache0Id ) ) . toBeUndefined ( )
219+ } )
220+ testInFiber ( 'Remove SofieIngestDataCache objects that are not connected to any Rundown' , async ( ) => {
221+ // Set up a mock rundown, a detached SofieIngestDataCache object and an object attached to the mock rundown
222+ // Detached SofieIngestDataCache object 0
223+ const dataCache0Id = protectString < SofieIngestDataCacheObjId > ( getRandomString ( ) )
224+ await SofieIngestDataCache . mutableCollection . insertAsync ( {
225+ _id : dataCache0Id ,
226+ data : {
227+ externalId : '' ,
228+ name : '' ,
229+ segments : [ ] ,
230+ type : '' ,
231+ rundownSource : { } as any ,
232+ userEditStates : { } ,
233+ payload : undefined ,
234+ } ,
235+ modified : new Date ( 2000 , 0 , 1 , 0 , 0 , 0 ) . getTime ( ) ,
236+ // this one is attached to rundown0
237+ rundownId : getRandomId ( ) ,
238+ type : SofieIngestCacheType . RUNDOWN ,
239+ } )
240+ // Attached SofieIngestDataCache object 1
241+ const dataCache1Id = protectString < SofieIngestDataCacheObjId > ( getRandomString ( ) )
242+ await SofieIngestDataCache . mutableCollection . insertAsync ( {
243+ _id : dataCache1Id ,
244+ data : {
245+ externalId : '' ,
246+ name : '' ,
247+ segments : [ ] ,
248+ type : '' ,
249+ rundownSource : { } as any ,
250+ userEditStates : { } ,
251+ payload : undefined ,
252+ } ,
253+ modified : new Date ( 2000 , 0 , 1 , 0 , 0 , 0 ) . getTime ( ) ,
254+ // just some random ID
255+ rundownId : rundownId ,
256+ type : SofieIngestCacheType . RUNDOWN ,
257+ } )
258+
259+ await runCronjobs ( )
260+
261+ expect ( await SofieIngestDataCache . findOneAsync ( dataCache1Id ) ) . toMatchObject ( {
262+ _id : dataCache1Id ,
263+ } )
264+ expect ( await SofieIngestDataCache . findOneAsync ( dataCache0Id ) ) . toBeUndefined ( )
212265 } )
213266 testInFiber ( 'Removes old PartInstances and PieceInstances' , async ( ) => {
214267 // nightlyCronjobInner()
@@ -217,7 +270,6 @@ describe('cronjobs', () => {
217270 _id : getRandomId < SegmentId > ( ) ,
218271 _rank : 0 ,
219272 externalId : '' ,
220- externalModified : 0 ,
221273 rundownId,
222274 name : 'mock segment' ,
223275 }
0 commit comments