Skip to content

Commit

Permalink
Merge branch 'upstream/fix-find-marker-position' into bbc-release52
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-dewit committed Oct 2, 2024
2 parents 273029b + 8384ba6 commit c57f790
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
11 changes: 5 additions & 6 deletions meteor/server/publications/lib/quickLoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,15 @@ export function findMarkerPosition(
marker: QuickLoopMarker,
fallback: number,
segmentCache: ReadonlyObjectDeep<ReactiveCacheCollection<Pick<DBSegment, '_id' | '_rank' | 'rundownId'>>>,
partCache:
| { parts: ReadonlyObjectDeep<ReactiveCacheCollection<Pick<DBPart, '_id' | '_rank' | 'segmentId'>>> }
| { partInstances: ReadonlyObjectDeep<ReactiveCacheCollection<DBPartInstance>> },
partCache: {
parts?: ReadonlyObjectDeep<ReactiveCacheCollection<Pick<DBPart, '_id' | '_rank' | 'segmentId'>>>
partInstances?: ReadonlyObjectDeep<ReactiveCacheCollection<DBPartInstance>>
},
rundownRanks: Record<string, number>
): MarkerPosition {
const part =
marker.type === QuickLoopMarkerType.PART
? 'parts' in partCache
? partCache.parts.findOne(marker.id)
: partCache.partInstances.findOne({ 'part._id': marker.id })?.part
? partCache.partInstances?.findOne({ 'part._id': marker.id })?.part ?? partCache.parts?.findOne(marker.id)
: undefined
const partRank = part?._rank ?? fallback

Expand Down
4 changes: 2 additions & 2 deletions meteor/server/publications/partInstancesUI/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export async function manipulateUIPartInstancesPublicationData(
playlist.quickLoop.start,
-Infinity,
state.contentCache.Segments,
{ partInstances: state.contentCache.PartInstances },
{ partInstances: state.contentCache.PartInstances, parts: state.contentCache.Parts },
rundownRanks
)
const quickLoopEndPosition =
Expand All @@ -171,7 +171,7 @@ export async function manipulateUIPartInstancesPublicationData(
playlist.quickLoop.end,
Infinity,
state.contentCache.Segments,
{ partInstances: state.contentCache.PartInstances },
{ partInstances: state.contentCache.PartInstances, parts: state.contentCache.Parts },
rundownRanks
)

Expand Down
11 changes: 11 additions & 0 deletions meteor/server/publications/partInstancesUI/reactiveContentCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MongoFieldSpecifierOnesStrict, MongoFieldSpecifierZeroes } from '@sofie
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
import { DBStudio } from '@sofie-automation/corelib/dist/dataModel/Studio'
import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'

export type RundownPlaylistCompact = Pick<DBRundownPlaylist, '_id' | 'activationId' | 'quickLoop' | 'rundownIdsInOrder'>
export const rundownPlaylistFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<RundownPlaylistCompact>>({
Expand All @@ -21,6 +22,14 @@ export const segmentFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<Pick<
rundownId: 1,
})

export type PartFields = '_id' | '_rank' | 'rundownId' | 'segmentId'
export const partFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<Pick<DBPart, PartFields>>>({
_id: 1,
_rank: 1,
segmentId: 1,
rundownId: 1,
})

export type PartInstanceOmitedFields = 'part.privateData'
export const partInstanceFieldSpecifier = literal<MongoFieldSpecifierZeroes<DBPartInstance>>({
// @ts-expect-error Mongo typings aren't clever enough yet
Expand All @@ -36,6 +45,7 @@ export const studioFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<Pick<D
export interface ContentCache {
Studios: ReactiveCacheCollection<Pick<DBStudio, StudioFields>>
Segments: ReactiveCacheCollection<Pick<DBSegment, SegmentFields>>
Parts: ReactiveCacheCollection<Pick<DBPart, PartFields>>
PartInstances: ReactiveCacheCollection<Omit<DBPartInstance, PartInstanceOmitedFields>>
RundownPlaylists: ReactiveCacheCollection<RundownPlaylistCompact>
}
Expand All @@ -44,6 +54,7 @@ export function createReactiveContentCache(): ContentCache {
const cache: ContentCache = {
Studios: new ReactiveCacheCollection<Pick<DBStudio, StudioFields>>('studios'),
Segments: new ReactiveCacheCollection<Pick<DBSegment, SegmentFields>>('segments'),
Parts: new ReactiveCacheCollection<Pick<DBPart, PartFields>>('parts'),
PartInstances: new ReactiveCacheCollection<Omit<DBPartInstance, PartInstanceOmitedFields>>('partInstances'),
RundownPlaylists: new ReactiveCacheCollection<RundownPlaylistCompact>('rundownPlaylists'),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { RundownId, RundownPlaylistActivationId, StudioId } from '@sofie-automat
import { logger } from '../../logging'
import {
ContentCache,
partFieldSpecifier,
partInstanceFieldSpecifier,
rundownPlaylistFieldSpecifier,
segmentFieldSpecifier,
studioFieldSpecifier,
} from './reactiveContentCache'
import { PartInstances, RundownPlaylists, Segments, Studios } from '../../collections'
import { PartInstances, Parts, RundownPlaylists, Segments, Studios } from '../../collections'

export class RundownContentObserver {
#observers: Meteor.LiveQueryHandle[] = []
Expand Down Expand Up @@ -53,6 +54,17 @@ export class RundownContentObserver {
projection: segmentFieldSpecifier,
}
),
Parts.observeChanges(
{
rundownId: {
$in: rundownIds,
},
},
cache.Parts.link(),
{
projection: partFieldSpecifier,
}
),
PartInstances.observeChanges(
{
rundownId: {
Expand Down

0 comments on commit c57f790

Please sign in to comment.