Skip to content

Commit eeaa00d

Browse files
committed
wip: hack out old flow
1 parent c7ec12e commit eeaa00d

File tree

6 files changed

+202
-229
lines changed

6 files changed

+202
-229
lines changed

meteor/server/publications/packageManager/expectedPackages/contentCache.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@ import { ReactiveCacheCollection } from '../../lib/ReactiveCacheCollection'
22
import { literal } from '@sofie-automation/corelib/dist/lib'
33
import { MongoFieldSpecifierOnesStrict } from '@sofie-automation/corelib/dist/mongo'
44
import { ExpectedPackageDB } from '@sofie-automation/corelib/dist/dataModel/ExpectedPackages'
5-
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
6-
import { PieceInstance, PieceInstancePiece } from '@sofie-automation/corelib/dist/dataModel/PieceInstance'
7-
8-
export type RundownPlaylistCompact = Pick<
9-
DBRundownPlaylist,
10-
'_id' | 'activationId' | 'currentPartInfo' | 'nextPartInfo'
11-
>
12-
export const rundownPlaylistFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<RundownPlaylistCompact>>({
13-
_id: 1,
14-
activationId: 1,
15-
currentPartInfo: 1, // So that it invalidates when the current changes
16-
nextPartInfo: 1, // So that it invalidates when the next changes
17-
})
18-
19-
export type PieceInstanceCompact = Pick<PieceInstance, '_id' | 'rundownId'> & {
20-
piece: Pick<PieceInstancePiece, 'expectedPackages'>
21-
}
22-
23-
export const pieceInstanceFieldsSpecifier = literal<MongoFieldSpecifierOnesStrict<PieceInstanceCompact>>({
24-
_id: 1,
25-
rundownId: 1,
26-
piece: {
27-
expectedPackages: 1,
28-
},
29-
})
5+
// import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
6+
// import { PieceInstance, PieceInstancePiece } from '@sofie-automation/corelib/dist/dataModel/PieceInstance'
7+
8+
// export type RundownPlaylistCompact = Pick<
9+
// DBRundownPlaylist,
10+
// '_id' | 'activationId' | 'currentPartInfo' | 'nextPartInfo'
11+
// >
12+
// export const rundownPlaylistFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<RundownPlaylistCompact>>({
13+
// _id: 1,
14+
// activationId: 1,
15+
// currentPartInfo: 1, // So that it invalidates when the current changes
16+
// nextPartInfo: 1, // So that it invalidates when the next changes
17+
// })
18+
19+
// export type PieceInstanceCompact = Pick<PieceInstance, '_id' | 'rundownId'> & {
20+
// piece: Pick<PieceInstancePiece, 'expectedPackages'>
21+
// }
22+
23+
// export const pieceInstanceFieldsSpecifier = literal<MongoFieldSpecifierOnesStrict<PieceInstanceCompact>>({
24+
// _id: 1,
25+
// rundownId: 1,
26+
// piece: {
27+
// expectedPackages: 1,
28+
// },
29+
// })
3030

3131
export type ExpectedPackageDBCompact = Pick<ExpectedPackageDB, '_id' | 'package'>
3232

@@ -37,15 +37,15 @@ export const expectedPackageDBFieldsSpecifier = literal<MongoFieldSpecifierOnesS
3737

3838
export interface ExpectedPackagesContentCache {
3939
ExpectedPackages: ReactiveCacheCollection<ExpectedPackageDBCompact>
40-
RundownPlaylists: ReactiveCacheCollection<RundownPlaylistCompact>
41-
PieceInstances: ReactiveCacheCollection<PieceInstanceCompact>
40+
// RundownPlaylists: ReactiveCacheCollection<RundownPlaylistCompact>
41+
// PieceInstances: ReactiveCacheCollection<PieceInstanceCompact>
4242
}
4343

4444
export function createReactiveContentCache(): ExpectedPackagesContentCache {
4545
const cache: ExpectedPackagesContentCache = {
4646
ExpectedPackages: new ReactiveCacheCollection<ExpectedPackageDBCompact>('expectedPackages'),
47-
RundownPlaylists: new ReactiveCacheCollection<RundownPlaylistCompact>('rundownPlaylists'),
48-
PieceInstances: new ReactiveCacheCollection<PieceInstanceCompact>('pieceInstances'),
47+
// RundownPlaylists: new ReactiveCacheCollection<RundownPlaylistCompact>('rundownPlaylists'),
48+
// PieceInstances: new ReactiveCacheCollection<PieceInstanceCompact>('pieceInstances'),
4949
}
5050

5151
return cache

meteor/server/publications/packageManager/expectedPackages/contentObserver.ts

Lines changed: 66 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
import { 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'
33
import { 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'
146
import { waitForAllObserversReady } from '../../lib/lib'
157

16-
const REACTIVITY_DEBOUNCE = 20
8+
// const REACTIVITY_DEBOUNCE = 20
179

1810
export 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

Comments
 (0)