11import { Meteor } from 'meteor/meteor'
2- import { PartInstanceId , StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids'
2+ import { StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids'
33import { logger } from '../../../logging'
4- import {
5- ExpectedPackagesContentCache ,
6- rundownPlaylistFieldSpecifier ,
7- pieceInstanceFieldsSpecifier ,
8- expectedPackageDBFieldsSpecifier ,
9- } from './contentCache'
10- import { ExpectedPackages , PieceInstances , RundownPlaylists } from '../../../collections'
11- import { ReactiveMongoObserverGroup , ReactiveMongoObserverGroupHandle } from '../../lib/observerGroup'
12- import _ from 'underscore'
13- import { equivalentArrays } from '@sofie-automation/shared-lib/dist/lib/lib'
4+ import { ExpectedPackagesContentCache , expectedPackageDBFieldsSpecifier } from './contentCache'
5+ import { ExpectedPackages } from '../../../collections'
146import { waitForAllObserversReady } from '../../lib/lib'
157
16- const REACTIVITY_DEBOUNCE = 20
8+ // const REACTIVITY_DEBOUNCE = 20
179
1810export class ExpectedPackagesContentObserver implements Meteor . LiveQueryHandle {
1911 #observers: Meteor . LiveQueryHandle [ ] = [ ]
2012 #cache: ExpectedPackagesContentCache
2113
22- #partInstanceIds: PartInstanceId [ ] = [ ]
23- #partInstanceIdObserver! : ReactiveMongoObserverGroupHandle
14+ // #partInstanceIds: PartInstanceId[] = []
15+ // // #partInstanceIdObserver!: ReactiveMongoObserverGroupHandle
2416
25- #disposed = false
17+ // #disposed = false
2618
2719 private constructor ( cache : ExpectedPackagesContentCache ) {
2820 this . #cache = cache
@@ -36,24 +28,24 @@ export class ExpectedPackagesContentObserver implements Meteor.LiveQueryHandle {
3628
3729 const observer = new ExpectedPackagesContentObserver ( cache )
3830
39- // Run the ShowStyleBase query in a ReactiveMongoObserverGroup, so that it can be restarted whenever
40- observer . #partInstanceIdObserver = await ReactiveMongoObserverGroup ( async ( ) => {
41- // Clear already cached data
42- cache . PieceInstances . remove ( { } )
43-
44- return [
45- PieceInstances . observeChanges (
46- {
47- // We can use the `this.#partInstanceIds` here, as this is restarted every time that property changes
48- partInstanceId : { $in : observer . #partInstanceIds } ,
49- } ,
50- cache . PieceInstances . link ( ) ,
51- {
52- projection : pieceInstanceFieldsSpecifier ,
53- }
54- ) ,
55- ]
56- } )
31+ // // Run the ShowStyleBase query in a ReactiveMongoObserverGroup, so that it can be restarted whenever
32+ // observer.#partInstanceIdObserver = await ReactiveMongoObserverGroup(async () => {
33+ // // Clear already cached data
34+ // cache.PieceInstances.remove({})
35+
36+ // return [
37+ // PieceInstances.observeChanges(
38+ // {
39+ // // We can use the `this.#partInstanceIds` here, as this is restarted every time that property changes
40+ // partInstanceId: { $in: observer.#partInstanceIds },
41+ // },
42+ // cache.PieceInstances.link(),
43+ // {
44+ // projection: pieceInstanceFieldsSpecifier,
45+ // }
46+ // ),
47+ // ]
48+ // })
5749
5850 // Subscribe to the database, and pipe any updates into the ReactiveCacheCollections
5951 // This takes ownership of the #partInstanceIdObserver, and will stop it if this throws
@@ -68,58 +60,58 @@ export class ExpectedPackagesContentObserver implements Meteor.LiveQueryHandle {
6860 }
6961 ) ,
7062
71- RundownPlaylists . observeChanges (
72- {
73- studioId : studioId ,
74- } ,
75- cache . RundownPlaylists . link ( ( ) => {
76- observer . updatePartInstanceIds ( )
77- } ) ,
78- {
79- fields : rundownPlaylistFieldSpecifier ,
80- }
81- ) ,
82-
83- observer . #partInstanceIdObserver,
63+ // RundownPlaylists.observeChanges(
64+ // {
65+ // studioId: studioId,
66+ // },
67+ // cache.RundownPlaylists.link(() => {
68+ // observer.updatePartInstanceIds()
69+ // }),
70+ // {
71+ // fields: rundownPlaylistFieldSpecifier,
72+ // }
73+ // ),
74+
75+ // observer.#partInstanceIdObserver,
8476 ] )
8577
8678 return observer
8779 }
8880
89- private updatePartInstanceIds = _ . debounce (
90- Meteor . bindEnvironment ( ( ) => {
91- if ( this . #disposed) return
92-
93- const newPartInstanceIdsSet = new Set < PartInstanceId > ( )
94-
95- this . #cache. RundownPlaylists . find ( { } ) . forEach ( ( playlist ) => {
96- if ( playlist . activationId ) {
97- if ( playlist . nextPartInfo ) {
98- newPartInstanceIdsSet . add ( playlist . nextPartInfo . partInstanceId )
99- }
100- if ( playlist . currentPartInfo ) {
101- newPartInstanceIdsSet . add ( playlist . currentPartInfo . partInstanceId )
102- }
103- }
104- } )
105-
106- const newPartInstanceIds = Array . from ( newPartInstanceIdsSet )
107-
108- if ( ! equivalentArrays ( newPartInstanceIds , this . #partInstanceIds) ) {
109- this . #partInstanceIds = newPartInstanceIds
110- // trigger the rundown group to restart
111- this . #partInstanceIdObserver. restart ( )
112- }
113- } ) ,
114- REACTIVITY_DEBOUNCE
115- )
81+ // private updatePartInstanceIds = _.debounce(
82+ // Meteor.bindEnvironment(() => {
83+ // if (this.#disposed) return
84+
85+ // const newPartInstanceIdsSet = new Set<PartInstanceId>()
86+
87+ // this.#cache.RundownPlaylists.find({}).forEach((playlist) => {
88+ // if (playlist.activationId) {
89+ // if (playlist.nextPartInfo) {
90+ // newPartInstanceIdsSet.add(playlist.nextPartInfo.partInstanceId)
91+ // }
92+ // if (playlist.currentPartInfo) {
93+ // newPartInstanceIdsSet.add(playlist.currentPartInfo.partInstanceId)
94+ // }
95+ // }
96+ // })
97+
98+ // const newPartInstanceIds = Array.from(newPartInstanceIdsSet)
99+
100+ // if (!equivalentArrays(newPartInstanceIds, this.#partInstanceIds)) {
101+ // this.#partInstanceIds = newPartInstanceIds
102+ // // trigger the rundown group to restart
103+ // this.#partInstanceIdObserver.restart()
104+ // }
105+ // }),
106+ // REACTIVITY_DEBOUNCE
107+ // )
116108
117109 public get cache ( ) : ExpectedPackagesContentCache {
118110 return this . #cache
119111 }
120112
121113 public stop = ( ) : void => {
122- this . #disposed = true
114+ // this.#disposed = true
123115
124116 this . #observers. forEach ( ( observer ) => observer . stop ( ) )
125117 }
0 commit comments