Skip to content

Commit c7e44cd

Browse files
authored
Merge pull request Sofie-Automation#1280 from nrkno/fix/bucketAdLibsRerankedOnRegeneration
2 parents 3fd22ef + 198ccaf commit c7e44cd

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

packages/job-worker/src/blueprints/postProcess.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ export function postProcessBucketAdLib(
397397
blueprintId: BlueprintId,
398398
bucketId: BucketId,
399399
rank: number | undefined,
400+
name: string | undefined,
400401
importVersions: RundownImportVersions
401402
): BucketAdLib {
402403
const id: PieceId = protectString(
@@ -416,6 +417,7 @@ export function postProcessBucketAdLib(
416417
importVersions,
417418
ingestInfo,
418419
_rank: rank || itemOrig._rank,
420+
name: name || itemOrig.name,
419421
timelineObjectsString: EmptyPieceTimelineObjectsBlob,
420422
}
421423
// Fill in ids of unnamed expectedPackages
@@ -446,6 +448,7 @@ export function postProcessBucketAction(
446448
blueprintId: BlueprintId,
447449
bucketId: BucketId,
448450
rank: number | undefined,
451+
label: string | undefined,
449452
importVersions: RundownImportVersions
450453
): BucketAdLibAction {
451454
const id: AdLibActionId = protectString(
@@ -463,7 +466,7 @@ export function postProcessBucketAction(
463466
bucketId,
464467
importVersions,
465468
ingestInfo,
466-
...processAdLibActionITranslatableMessages(itemOrig, blueprintId, rank),
469+
...processAdLibActionITranslatableMessages(itemOrig, blueprintId, rank, label),
467470
}
468471

469472
// Fill in ids of unnamed expectedPackages
@@ -498,12 +501,12 @@ function processAdLibActionITranslatableMessages<
498501
})[]
499502
},
500503
T extends IBlueprintActionManifest
501-
>(itemOrig: T, blueprintId: BlueprintId, rank?: number): Pick<K, 'display' | 'triggerModes'> {
504+
>(itemOrig: T, blueprintId: BlueprintId, rank?: number, label?: string): Pick<K, 'display' | 'triggerModes'> {
502505
return {
503506
display: {
504507
...itemOrig.display,
505508
_rank: rank ?? itemOrig.display._rank,
506-
label: wrapTranslatableMessageFromBlueprints(itemOrig.display.label, [blueprintId]),
509+
label: (label as any) ?? wrapTranslatableMessageFromBlueprints(itemOrig.display.label, [blueprintId]),
507510
triggerLabel:
508511
itemOrig.display.triggerLabel &&
509512
wrapTranslatableMessageFromBlueprints(itemOrig.display.triggerLabel, [blueprintId]),

packages/job-worker/src/ingest/bucket/import.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ import { BucketId, ShowStyleBaseId } from '@sofie-automation/corelib/dist/dataMo
3030
import { ExpectedPackageDBType } from '@sofie-automation/corelib/dist/dataModel/ExpectedPackages'
3131

3232
export async function handleBucketItemImport(context: JobContext, data: BucketItemImportProps): Promise<void> {
33-
await regenerateBucketItemFromIngestInfo(context, data.bucketId, data.showStyleBaseId, {
34-
limitToShowStyleVariantIds: data.showStyleVariantIds,
35-
payload: data.payload,
36-
})
33+
await regenerateBucketItemFromIngestInfo(
34+
context,
35+
data.bucketId,
36+
data.showStyleBaseId,
37+
{
38+
limitToShowStyleVariantIds: data.showStyleVariantIds,
39+
payload: data.payload,
40+
},
41+
undefined,
42+
undefined
43+
)
3744
}
3845

3946
export async function handleBucketItemRegenerate(context: JobContext, data: BucketItemRegenerateProps): Promise<void> {
@@ -49,9 +56,11 @@ export async function handleBucketItemRegenerate(context: JobContext, data: Buck
4956
projection: {
5057
showStyleBaseId: 1,
5158
ingestInfo: 1,
59+
name: 1,
60+
_rank: 1,
5261
},
5362
}
54-
) as Promise<Pick<BucketAdLib, 'showStyleBaseId' | 'ingestInfo'>> | undefined,
63+
) as Promise<Pick<BucketAdLib, 'showStyleBaseId' | 'ingestInfo' | 'name' | '_rank'>> | undefined,
5564
context.directCollections.BucketAdLibActions.findOne(
5665
{
5766
externalId: data.externalId,
@@ -62,9 +71,10 @@ export async function handleBucketItemRegenerate(context: JobContext, data: Buck
6271
projection: {
6372
showStyleBaseId: 1,
6473
ingestInfo: 1,
74+
display: 1,
6575
},
6676
}
67-
) as Promise<Pick<BucketAdLibAction, 'showStyleBaseId' | 'ingestInfo'>> | undefined,
77+
) as Promise<Pick<BucketAdLibAction, 'showStyleBaseId' | 'ingestInfo' | 'display'>> | undefined,
6878
])
6979

7080
// TODO - UserErrors?
@@ -74,15 +84,19 @@ export async function handleBucketItemRegenerate(context: JobContext, data: Buck
7484
context,
7585
data.bucketId,
7686
adlibAction.showStyleBaseId,
77-
adlibAction.ingestInfo
87+
adlibAction.ingestInfo,
88+
adlibAction.display._rank,
89+
typeof adlibAction.display.label === 'string' ? adlibAction.display.label : undefined
7890
)
7991
} else if (adlibPiece) {
8092
if (!adlibPiece.ingestInfo) throw new Error(`Bucket AdLibPiece cannot be resynced, it has no ingest data`)
8193
await regenerateBucketItemFromIngestInfo(
8294
context,
8395
data.bucketId,
8496
adlibPiece.showStyleBaseId,
85-
adlibPiece.ingestInfo
97+
adlibPiece.ingestInfo,
98+
adlibPiece._rank,
99+
adlibPiece.name
86100
)
87101
} else {
88102
throw new Error(`No Bucket Items with externalId "${data.externalId}" were found`)
@@ -93,7 +107,9 @@ async function regenerateBucketItemFromIngestInfo(
93107
context: JobContext,
94108
bucketId: BucketId,
95109
showStyleBaseId: ShowStyleBaseId,
96-
ingestInfo: BucketAdLibIngestInfo
110+
ingestInfo: BucketAdLibIngestInfo,
111+
oldRank: number | undefined,
112+
oldLabel: string | undefined
97113
): Promise<void> {
98114
const [showStyleBase, allShowStyleVariants, allOldAdLibPieces, allOldAdLibActions, blueprint] = await Promise.all([
99115
context.getShowStyleBase(showStyleBaseId),
@@ -130,7 +146,7 @@ async function regenerateBucketItemFromIngestInfo(
130146
const actionIdsToRemove = new Set(allOldAdLibActions.map((p) => p._id))
131147

132148
let isFirstShowStyleVariant = true
133-
let newRank: number | undefined = undefined
149+
const newRank: number | undefined = oldRank ?? (await calculateHighestRankInBucket(context, bucketId)) + 1
134150
let onlyGenerateOneItem = false
135151

136152
const ps: Promise<any>[] = []
@@ -150,13 +166,6 @@ async function regenerateBucketItemFromIngestInfo(
150166
core: getSystemVersion(),
151167
}
152168

153-
// Cache the newRank, so we only have to calculate it once:
154-
if (newRank === undefined) {
155-
newRank = (await calculateHighestRankInBucket(context, bucketId)) + 1
156-
} else {
157-
newRank++
158-
}
159-
160169
if (isAdlibAction(rawAdlib)) {
161170
if (isFirstShowStyleVariant) {
162171
if (rawAdlib.allVariants) {
@@ -174,6 +183,7 @@ async function regenerateBucketItemFromIngestInfo(
174183
blueprint.blueprintId,
175184
bucketId,
176185
newRank,
186+
oldLabel,
177187
importVersions
178188
)
179189

@@ -194,6 +204,7 @@ async function regenerateBucketItemFromIngestInfo(
194204
blueprint.blueprintId,
195205
bucketId,
196206
newRank,
207+
oldLabel,
197208
importVersions
198209
)
199210

0 commit comments

Comments
 (0)