diff --git a/apps/server/src/services/rundown-service/__tests__/rundownCache.test.ts b/apps/server/src/services/rundown-service/__tests__/rundownCache.test.ts index d2fe02e5c..db2f8773a 100644 --- a/apps/server/src/services/rundown-service/__tests__/rundownCache.test.ts +++ b/apps/server/src/services/rundown-service/__tests__/rundownCache.test.ts @@ -24,6 +24,7 @@ import { createCustomField, editCustomField, removeCustomField, + customFieldChangelog, } from '../rundownCache.js'; describe('generate()', () => { @@ -870,9 +871,56 @@ describe('custom fields', () => { }; const customField = await editCustomField('sound', { label: 'Sound', type: 'string', colour: 'green' }); + expect(customFieldChangelog).toStrictEqual({}); expect(customField).toStrictEqual(expected); }); + + it('renames a field to a new label', async () => { + const created = await createCustomField({ label: 'Video', type: 'string', colour: 'red' }); + + const expected = { + lighting: { + label: 'Lighting', + type: 'string', + colour: 'blue', + }, + sound: { + label: 'Sound', + type: 'string', + colour: 'green', + }, + video: { + label: 'Video', + type: 'string', + colour: 'red', + }, + }; + + expect(created).toStrictEqual(expected); + + const expectedAfter = { + lighting: { + label: 'Lighting', + type: 'string', + colour: 'blue', + }, + sound: { + label: 'Sound', + type: 'string', + colour: 'green', + }, + av: { + label: 'AV', + type: 'string', + colour: 'red', + }, + }; + + const customField = await editCustomField('video', { label: 'AV', type: 'string', colour: 'red' }); + expect(customField).toStrictEqual(expectedAfter); + expect(customFieldChangelog).toStrictEqual({ video: 'av' }); + }); }); describe('removeCustomField()', () => { @@ -883,6 +931,11 @@ describe('custom fields', () => { type: 'string', colour: 'blue', }, + av: { + label: 'AV', + type: 'string', + colour: 'red', + }, }; const customField = await removeCustomField('sound'); diff --git a/apps/server/src/services/rundown-service/rundownCache.ts b/apps/server/src/services/rundown-service/rundownCache.ts index e2851b96d..655b73625 100644 --- a/apps/server/src/services/rundown-service/rundownCache.ts +++ b/apps/server/src/services/rundown-service/rundownCache.ts @@ -39,7 +39,7 @@ let lastEnd: MaybeNumber = null; let links: Record = {}; /** - * Object that contains renamings to custom fields + * Object that contains reference of renamed custom fields * Used to rename the custom fields in the events * @example * { @@ -47,7 +47,7 @@ let links: Record = {}; * lighting: lx * } */ -const customFieldChangelog = {}; +export const customFieldChangelog = {}; /** * Keep track of which custom fields are used. @@ -176,9 +176,7 @@ type RundownCache = { */ export function get(): Readonly { if (isStale) { - console.time('rundownCache__init'); generate(); - console.timeEnd('rundownCache__init'); } return { rundown, @@ -194,9 +192,7 @@ export function get(): Readonly { */ export function getMetadata() { if (isStale) { - console.time('rundownCache__init'); generate(); - console.timeEnd('rundownCache__init'); } return { @@ -237,9 +233,7 @@ export function mutateCache(mutation: MutatingFn) { // schedule a non priority cache update setImmediate(() => { - console.time('rundownCache__init'); get(); - console.timeEnd('rundownCache__init'); }); // defer writing to the database @@ -410,14 +404,12 @@ function invalidateIfUsed(label: CustomFieldLabel) { // ... and schedule a cache update // schedule a non priority cache update setImmediate(() => { - console.time('rundownCache__init'); generate(); - console.timeEnd('rundownCache__init'); }); } /** - * Scheduløes a non priority custom field persist + * Schedules a non priority custom field persist * @param persistedCustomFields */ function scheduleCustomFieldPersist(persistedCustomFields: CustomFields) {