Skip to content

Commit

Permalink
feat: Improve performance of OnShowStyleEnd infinites
Browse files Browse the repository at this point in the history
  • Loading branch information
eol-account committed May 28, 2021
1 parent ad4649b commit dcf30c6
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 12 deletions.
4 changes: 3 additions & 1 deletion meteor/client/lib/rundown.ts
Expand Up @@ -21,7 +21,7 @@ import {
} from '../../lib/Rundown'
import { DBSegment, Segment, SegmentId, Segments } from '../../lib/collections/Segments'
import { RundownPlaylist } from '../../lib/collections/RundownPlaylists'
import { ShowStyleBase } from '../../lib/collections/ShowStyleBases'
import { ShowStyleBase, ShowStyleBaseId } from '../../lib/collections/ShowStyleBases'
import { literal, normalizeArray, getCurrentTime, applyToArray, unprotectString, protectString } from '../../lib/lib'
import { PartInstance, wrapPartToTemporaryInstance } from '../../lib/collections/PartInstances'
import { PieceId } from '../../lib/collections/Pieces'
Expand Down Expand Up @@ -310,6 +310,7 @@ export namespace RundownUtils {
segment: DBSegment,
segmentsBeforeThisInRundownSet: Set<SegmentId>,
rundownsBeforeThisInPlaylistSet: Set<RundownId>,
rundownsToShowstyles: Map<RundownId, ShowStyleBaseId>,
orderedAllPartIds: PartId[],
currentPartInstance: PartInstance | undefined,
nextPartInstance: PartInstance | undefined,
Expand Down Expand Up @@ -483,6 +484,7 @@ export namespace RundownUtils {
new Set(partIds.slice(0, itIndex)),
segmentsBeforeThisInRundownSet,
rundownsBeforeThisInPlaylistSet,
rundownsToShowstyles,
orderedAllPartIds,
nextPartIsAfterCurrentPart,
currentPartInstance,
Expand Down
8 changes: 8 additions & 0 deletions meteor/client/ui/ClockView/PresenterScreen.tsx
Expand Up @@ -54,6 +54,7 @@ function getShowStyleBaseIdSegmentPartUi(
segments: Segment[]
parts: Part[]
},
rundownsToShowstyles: Map<RundownId, ShowStyleBaseId>,
currentPartInstance: PartInstance | undefined,
nextPartInstance: PartInstance | undefined
): {
Expand Down Expand Up @@ -94,6 +95,7 @@ function getShowStyleBaseIdSegmentPartUi(
orderedSegmentsAndParts.segments[segmentIndex],
new Set(orderedSegmentsAndParts.segments.map((s) => s._id).slice(0, segmentIndex)),
new Set(rundownOrder.slice(0, rundownIndex)),
rundownsToShowstyles,
orderedSegmentsAndParts.parts.map((part) => part._id),
currentPartInstance,
nextPartInstance,
Expand Down Expand Up @@ -147,6 +149,10 @@ export const getPresenterScreenReactive = (props: RundownOverviewProps): Rundown
rundowns = playlist.getRundowns()
const orderedSegmentsAndParts = playlist.getSegmentsAndPartsSync()
rundownIds = rundowns.map((rundown) => rundown._id)
const rundownsToShowstyles: Map<RundownId, ShowStyleBaseId> = new Map()
for (let rundown of rundowns) {
rundownsToShowstyles.set(rundown._id, rundown.showStyleBaseId)
}
showStyleBaseIds = rundowns.map((rundown) => rundown.showStyleBaseId)
const { currentPartInstance, nextPartInstance } = playlist.getSelectedPartInstances()
const partInstance = currentPartInstance || nextPartInstance
Expand All @@ -173,6 +179,7 @@ export const getPresenterScreenReactive = (props: RundownOverviewProps): Rundown
currentPartInstance,
playlist,
orderedSegmentsAndParts,
rundownsToShowstyles,
currentPartInstance,
nextPartInstance
)
Expand All @@ -186,6 +193,7 @@ export const getPresenterScreenReactive = (props: RundownOverviewProps): Rundown
nextPartInstance,
playlist,
orderedSegmentsAndParts,
rundownsToShowstyles,
currentPartInstance,
nextPartInstance
)
Expand Down
10 changes: 9 additions & 1 deletion meteor/client/ui/RundownView.tsx
Expand Up @@ -53,7 +53,7 @@ import { AfterBroadcastForm } from './AfterBroadcastForm'
import { Tracker } from 'meteor/tracker'
import { RundownRightHandControls } from './RundownView/RundownRightHandControls'
import { mousetrapHelper } from '../lib/mousetrapHelper'
import { ShowStyleBases, ShowStyleBase } from '../../lib/collections/ShowStyleBases'
import { ShowStyleBases, ShowStyleBase, ShowStyleBaseId } from '../../lib/collections/ShowStyleBases'
import { PeripheralDevicesAPI, callPeripheralDeviceFunction } from '../lib/clientAPI'
import {
RONotificationEvent,
Expand Down Expand Up @@ -1412,6 +1412,7 @@ interface ITrackedProps {
rundowns: Rundown[]
playlist?: RundownPlaylist
matchedSegments: MatchedSegment[]
rundownsToShowstyles: Map<RundownId, ShowStyleBaseId>
studio?: Studio
showStyleBase?: ShowStyleBase
rundownLayouts?: Array<RundownLayoutBase>
Expand Down Expand Up @@ -1454,6 +1455,11 @@ export const RundownView = translateWithTracker<IProps, IState, ITrackedProps>((
? undefined
: (params['buckets'] as string).split(',').map((v) => parseInt(v))

const rundownsToShowstyles: Map<RundownId, ShowStyleBaseId> = new Map()
for (let rundown of rundowns) {
rundownsToShowstyles.set(rundown._id, rundown.showStyleBaseId)
}

// let rundownDurations = calculateDurations(rundown, parts)
return {
rundownPlaylistId: playlistId,
Expand All @@ -1478,6 +1484,7 @@ export const RundownView = translateWithTracker<IProps, IState, ITrackedProps>((
),
}))
: [],
rundownsToShowstyles,
playlist,
studio: studio,
showStyleBase: rundowns.length > 0 ? ShowStyleBases.findOne(rundowns[0].showStyleBaseId) : undefined,
Expand Down Expand Up @@ -2267,6 +2274,7 @@ export const RundownView = translateWithTracker<IProps, IState, ITrackedProps>((
onSegmentScroll={this.onSegmentScroll}
segmentsIdsBefore={rundownAndSegments.segmentIdsBeforeEachSegment[segmentIndex]}
rundownIdsBefore={new Set(rundownArray.slice(0, rundownIndex).map((r) => r.rundown._id))}
rundownsToShowstyles={this.props.rundownsToShowstyles}
isLastSegment={
rundownIndex === rundownArray.length - 1 && segmentIndex === segmentArray.length - 1
}
Expand Down
Expand Up @@ -18,7 +18,7 @@ import {
SegmentExtended,
} from '../../../lib/Rundown'
import { IContextMenuContext, MAGIC_TIME_SCALE_FACTOR } from '../RundownView'
import { ShowStyleBase } from '../../../lib/collections/ShowStyleBases'
import { ShowStyleBase, ShowStyleBaseId } from '../../../lib/collections/ShowStyleBases'
import { SpeechSynthesiser } from '../../lib/speechSynthesis'
import { NoteType, SegmentNote } from '../../../lib/api/notes'
import { getElementWidth } from '../../utils/dimensions'
Expand Down Expand Up @@ -82,6 +82,7 @@ interface IProps {
segmentId: SegmentId
segmentsIdsBefore: Set<SegmentId>
rundownIdsBefore: Set<RundownId>
rundownsToShowstyles: Map<RundownId, ShowStyleBaseId>
studio: Studio
showStyleBase: ShowStyleBase
playlist: RundownPlaylist
Expand Down Expand Up @@ -200,6 +201,7 @@ export const SegmentTimelineContainer = translateWithTracker<IProps, IState, ITr
segment,
props.segmentsIdsBefore,
new Set(rundownOrder.slice(0, rundownIndex)),
props.rundownsToShowstyles,
orderedAllPartIds,
currentPartInstance,
nextPartInstance,
Expand Down
4 changes: 4 additions & 0 deletions meteor/lib/Rundown.ts
Expand Up @@ -16,6 +16,7 @@ import { invalidateAfter } from '../client/lib/invalidatingTime'
import { getCurrentTime, protectString, unprotectString } from './lib'
import { RundownPlaylistActivationId } from './collections/RundownPlaylists'
import { Rundown, RundownId } from './collections/Rundowns'
import { ShowStyleBaseId } from './collections/ShowStyleBases'

export interface SegmentExtended extends DBSegment {
/** Output layers available in the installation used by this segment */
Expand Down Expand Up @@ -123,6 +124,7 @@ export function getPieceInstancesForPartInstance(
partsBeforeThisInSegmentSet: Set<PartId>,
segmentsBeforeThisInRundownSet: Set<SegmentId>,
rundownsBeforeThisInPlaylistSet: Set<RundownId>,
rundownsToShowstyles: Map<RundownId, ShowStyleBaseId>,
orderedAllParts: PartId[],
nextPartIsAfterCurrentPart: boolean,
currentPartInstance: PartInstance | undefined,
Expand All @@ -140,6 +142,7 @@ export function getPieceInstancesForPartInstance(
partsBeforeThisInSegmentSet,
segmentsBeforeThisInRundownSet,
rundownsBeforeThisInPlaylistSet,
rundownsToShowstyles,
fetchPiecesThatMayBeActiveForPart(
partInstance.part,
partsBeforeThisInSegmentSet,
Expand Down Expand Up @@ -182,6 +185,7 @@ export function getPieceInstancesForPartInstance(
partsBeforeThisInSegmentSet,
segmentsBeforeThisInRundownSet,
rundownsBeforeThisInPlaylistSet,
rundownsToShowstyles,
fetchPiecesThatMayBeActiveForPart(
partInstance.part,
partsBeforeThisInSegmentSet,
Expand Down
19 changes: 12 additions & 7 deletions meteor/lib/rundown/infinites.ts
Expand Up @@ -16,7 +16,7 @@ import {
getRandomId,
} from '../lib'
import { Mongo } from 'meteor/mongo'
import { ShowStyleBase } from '../collections/ShowStyleBases'
import { ShowStyleBase, ShowStyleBaseId } from '../collections/ShowStyleBases'
import { getPieceGroupId } from './timeline'
import { RundownPlaylist, RundownPlaylistActivationId } from '../collections/RundownPlaylists'
import { ReadonlyDeep } from 'type-fest'
Expand Down Expand Up @@ -80,6 +80,7 @@ export function getPlayheadTrackingInfinitesForPart(
partsBeforeThisInSegmentSet: Set<PartId>,
segmentsBeforeThisInRundownSet: Set<SegmentId>,
rundownsBeforeThisInPlaylistSet: Set<RundownId>,
rundownsToShowstyles: Map<RundownId, ShowStyleBaseId>,
currentPartInstance: PartInstance,
currentPartPieceInstances: PieceInstance[],
rundown: Rundown,
Expand Down Expand Up @@ -195,14 +196,14 @@ export function getPlayheadTrackingInfinitesForPart(
break
}

const prevRundown = Rundowns.findOne(prevRundownId, { fields: { showStyleBaseId: 1 } })
const prevRundownShowstyle = rundownsToShowstyles.get(prevRundownId)

if (!prevRundown) {
if (!prevRundownShowstyle) {
isValid = false
break
}

isValid = prevRundown.showStyleBaseId === rundown.showStyleBaseId
isValid = prevRundownShowstyle === rundown.showStyleBaseId
}

if (isValid) {
Expand Down Expand Up @@ -260,6 +261,7 @@ export function isPiecePotentiallyActiveInPart(
partsBeforeThisInSegment: Set<PartId>,
segmentsBeforeThisInRundown: Set<SegmentId>,
rundownsBeforeThisInPlaylistSet: Set<RundownId>,
rundownsToShowstyles: Map<RundownId, ShowStyleBaseId>,
rundown: Rundown,
part: DBPart,
pieceToCheck: Piece
Expand Down Expand Up @@ -323,13 +325,13 @@ export function isPiecePotentiallyActiveInPart(
return false
}

const prevRundown = Rundowns.findOne(prevRundownId, { fields: { showStyleBaseId: 1 } })
const prevRundownShowstyle = rundownsToShowstyles.get(prevRundownId)

if (!prevRundown) {
if (!prevRundownShowstyle) {
return false
}

return prevRundown.showStyleBaseId === rundown.showStyleBaseId
return prevRundownShowstyle === rundown.showStyleBaseId
default:
assertNever(pieceToCheck.lifespan)
return false
Expand All @@ -345,6 +347,7 @@ export function getPieceInstancesForPart(
partsBeforeThisInSegmentSet: Set<PartId>,
segmentsBeforeThisInRundownSet: Set<SegmentId>,
rundownsBeforeThisInPlaylistSet: Set<RundownId>,
rundownsToShowstyles: Map<RundownId, ShowStyleBaseId>,
possiblePieces: Piece[],
orderedPartIds: PartId[],
newInstanceId: PartInstanceId,
Expand Down Expand Up @@ -390,6 +393,7 @@ export function getPieceInstancesForPart(
partsBeforeThisInSegmentSet,
segmentsBeforeThisInRundownSet,
rundownsBeforeThisInPlaylistSet,
rundownsToShowstyles,
rundown,
part,
candidatePiece
Expand All @@ -413,6 +417,7 @@ export function getPieceInstancesForPart(
partsBeforeThisInSegmentSet,
segmentsBeforeThisInRundownSet,
rundownsBeforeThisInPlaylistSet,
rundownsToShowstyles,
playingPartInstance,
playingPieceInstances || [],
rundown,
Expand Down
13 changes: 12 additions & 1 deletion meteor/server/api/playout/cache.ts
Expand Up @@ -10,7 +10,7 @@ import {
RundownPlaylistId,
RundownPlaylists,
} from '../../../lib/collections/RundownPlaylists'
import { Rundown, DBRundown, Rundowns } from '../../../lib/collections/Rundowns'
import { Rundown, DBRundown, Rundowns, RundownId } from '../../../lib/collections/Rundowns'
import { Segment, DBSegment, Segments } from '../../../lib/collections/Segments'
import { Studio, StudioId, Studios } from '../../../lib/collections/Studios'
import { Timeline, TimelineComplete } from '../../../lib/collections/Timeline'
Expand All @@ -24,6 +24,7 @@ import { CacheForStudioBase } from '../studio/cache'
import { getRundownsSegmentsAndPartsFromCache } from './lib'
import { CacheForIngest } from '../ingest/cache'
import { Meteor } from 'meteor/meteor'
import { ShowStyleBaseId } from '../../../lib/collections/ShowStyleBases'

/**
* This is a cache used for playout operations.
Expand Down Expand Up @@ -276,3 +277,13 @@ export function getSelectedPartInstancesFromCache(
: undefined,
}
}
export function getShowStyleIdsRundownMappingFromCache(cache: CacheForPlayout): Map<RundownId, ShowStyleBaseId> {
const rundowns = cache.Rundowns.findFetch({})
const ret = new Map()

for (let rundown of rundowns) {
ret.set(rundown._id, rundown.showStyleBaseId)
}

return ret
}
13 changes: 12 additions & 1 deletion meteor/server/api/playout/infinites.ts
Expand Up @@ -15,7 +15,12 @@ import {
} from '../../../lib/rundown/infinites'
import { profiler } from '../profiler'
import { Meteor } from 'meteor/meteor'
import { CacheForPlayout, getOrderedSegmentsAndPartsFromPlayoutCache, getSelectedPartInstancesFromCache } from './cache'
import {
CacheForPlayout,
getOrderedSegmentsAndPartsFromPlayoutCache,
getSelectedPartInstancesFromCache,
getShowStyleIdsRundownMappingFromCache,
} from './cache'
import { ReadonlyDeep } from 'type-fest'
import { asyncCollectionFindFetch } from '../../lib/database'
import { getCurrentTime } from '../../../lib/lib'
Expand Down Expand Up @@ -193,11 +198,14 @@ export async function syncPlayheadInfinitesForNextPartInstance(cache: CacheForPl
true
)

const rundownIdsToShowstyleIds = getShowStyleIdsRundownMappingFromCache(cache)

const infinites = libgetPlayheadTrackingInfinitesForPart(
playlist.activationId,
new Set(partsBeforeThisInSegment),
new Set(segmentsBeforeThisInRundown),
new Set(rundownsBeforeThisInPlaylist),
rundownIdsToShowstyleIds,
currentPartInstance,
prunedPieceInstances,
rundown,
Expand Down Expand Up @@ -250,6 +258,8 @@ export function getPieceInstancesForPart(
part
)

const rundownIdsToShowstyleIds = getShowStyleIdsRundownMappingFromCache(cache)

const res = libgetPieceInstancesForPart(
playlist.activationId,
playingPartInstance,
Expand All @@ -259,6 +269,7 @@ export function getPieceInstancesForPart(
new Set(partsBeforeThisInSegment),
new Set(segmentsBeforeThisInRundown),
new Set(rundownsBeforeThisInPlaylist),
rundownIdsToShowstyleIds,
possiblePieces,
orderedPartsAndSegments.parts.map((p) => p._id),
newInstanceId,
Expand Down

0 comments on commit dcf30c6

Please sign in to comment.