Skip to content

Commit

Permalink
fix: avoid excessive applyAndValidateOverrides
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Oct 9, 2024
1 parent 685364d commit 5ef7c34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { CustomPublishCollection } from '../../../lib/customPublication'
import { logger } from '../../../logging'
import { ExpectedPackagesContentCache } from './contentCache'
import type { StudioFields } from './publication'
import { applyAndValidateOverrides } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'

/**
* Regenerate the output for the provided ExpectedPackage `regenerateIds`, updating the data in `collection` as needed
Expand All @@ -32,13 +31,13 @@ export async function updateCollectionForExpectedPackageIds(
contentCache: ReadonlyDeep<ExpectedPackagesContentCache>,
studio: Pick<DBStudio, StudioFields>,
layerNameToDeviceIds: Map<string, PeripheralDeviceId[]>,
packageContainers: Record<string, StudioPackageContainer>,
collection: CustomPublishCollection<PackageManagerExpectedPackage>,
filterPlayoutDeviceIds: ReadonlyDeep<PeripheralDeviceId[]> | undefined,
regenerateIds: Set<ExpectedPackageId>
): Promise<void> {
const updatedDocIds = new Set<PackageManagerExpectedPackageId>()
const missingExpectedPackageIds = new Set<ExpectedPackageId>()
const packageContainers = applyAndValidateOverrides(studio.packageContainersWithOverrides).obj

for (const packageId of regenerateIds) {
const packageDoc = contentCache.ExpectedPackages.findOne(packageId)
Expand Down Expand Up @@ -102,13 +101,13 @@ export async function updateCollectionForPieceInstanceIds(
contentCache: ReadonlyDeep<ExpectedPackagesContentCache>,
studio: Pick<DBStudio, StudioFields>,
layerNameToDeviceIds: Map<string, PeripheralDeviceId[]>,
packageContainers: Record<string, StudioPackageContainer>,
collection: CustomPublishCollection<PackageManagerExpectedPackage>,
filterPlayoutDeviceIds: ReadonlyDeep<PeripheralDeviceId[]> | undefined,
regenerateIds: Set<PieceInstanceId>
): Promise<void> {
const updatedDocIds = new Set<PackageManagerExpectedPackageId>()
const missingPieceInstanceIds = new Set<PieceInstanceId>()
const packageContainers = applyAndValidateOverrides(studio.packageContainersWithOverrides).obj

for (const pieceInstanceId of regenerateIds) {
const pieceInstanceDoc = contentCache.PieceInstances.findOne(pieceInstanceId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor'
import { PeripheralDeviceReadAccess } from '../../../security/peripheralDevice'
import { DBStudio } from '@sofie-automation/corelib/dist/dataModel/Studio'
import { DBStudio, StudioPackageContainer } from '@sofie-automation/corelib/dist/dataModel/Studio'
import {
TriggerUpdate,
meteorCustomPublish,
Expand Down Expand Up @@ -48,6 +48,7 @@ interface ExpectedPackagesPublicationUpdateProps {
interface ExpectedPackagesPublicationState {
studio: Pick<DBStudio, StudioFields> | undefined
layerNameToDeviceIds: Map<string, PeripheralDeviceId[]>
packageContainers: Record<string, StudioPackageContainer>

contentCache: ReadonlyDeep<ExpectedPackagesContentCache>
}
Expand Down Expand Up @@ -122,6 +123,7 @@ async function manipulateExpectedPackagesPublicationData(
const invalidateAllItems = !updateProps || updateProps.newCache || updateProps.invalidateStudio

if (!state.layerNameToDeviceIds) state.layerNameToDeviceIds = new Map()
if (!state.packageContainers) state.packageContainers = {}

if (invalidateAllItems) {
// Everything is invalid, reset everything
Expand All @@ -141,12 +143,14 @@ async function manipulateExpectedPackagesPublicationData(
if (!state.studio) {
logger.warn(`Pub.expectedPackagesForDevice: studio "${args.studioId}" not found!`)
state.layerNameToDeviceIds = new Map()
state.packageContainers = {}
} else {
const studioMappings = applyAndValidateOverrides(state.studio.mappingsWithOverrides).obj
state.layerNameToDeviceIds = buildMappingsToDeviceIdMap(
applyAndValidateOverrides(state.studio.routeSetsWithOverrides).obj,
studioMappings
)
state.packageContainers = applyAndValidateOverrides(state.studio.packageContainersWithOverrides).obj
}
}

Expand All @@ -173,6 +177,7 @@ async function manipulateExpectedPackagesPublicationData(
state.contentCache,
state.studio,
state.layerNameToDeviceIds,
state.packageContainers,
collection,
args.filterPlayoutDeviceIds,
regenerateExpectedPackageIds
Expand All @@ -181,6 +186,7 @@ async function manipulateExpectedPackagesPublicationData(
state.contentCache,
state.studio,
state.layerNameToDeviceIds,
state.packageContainers,
collection,
args.filterPlayoutDeviceIds,
regeneratePieceInstanceIds
Expand Down

0 comments on commit 5ef7c34

Please sign in to comment.