From d6672865a59a94a2acdd3ec7e827f96f8c3e67e4 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 5 Nov 2023 17:52:25 -0400 Subject: data: withAlwaysReferenceByDirectory: micro-optimizations --- .../things/track/withAlwaysReferenceByDirectory.js | 29 ++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/data/composite/things/track/withAlwaysReferenceByDirectory.js b/src/data/composite/things/track/withAlwaysReferenceByDirectory.js index d27f7b23..52d72124 100644 --- a/src/data/composite/things/track/withAlwaysReferenceByDirectory.js +++ b/src/data/composite/things/track/withAlwaysReferenceByDirectory.js @@ -53,19 +53,28 @@ export default templateCompositeFrom({ // logic on a completely unrelated context. { dependencies: [input.myself(), 'trackData', 'originalReleaseTrack'], - compute: (continuation, { + compute(continuation, { [input.myself()]: thisTrack, ['trackData']: trackData, ['originalReleaseTrack']: ref, - }) => continuation({ - ['#originalRelease']: - (ref.startsWith('track:') - ? trackData.find(track => track.directory === ref.slice('track:'.length)) - : trackData.find(track => - track !== thisTrack && - !CacheableObject.getUpdateValue(track, 'originalReleaseTrack') && - track.name.toLowerCase() === ref.toLowerCase())), - }) + }) { + let originalRelease; + + if (ref.startsWith('track:')) { + const refDirectory = ref.slice('track:'.length); + originalRelease = + trackData.find(track => track.directory === refDirectory); + } else { + const refName = ref.toLowerCase(); + originalRelease = + trackData.find(track => + track.name.toLowerCase() === refName && + track !== thisTrack && + !CacheableObject.getUpdateValue(track, 'originalReleaseTrack')); + } + + return continuation({['#originalRelease']: originalRelease}); + }, }, exitWithoutDependency({ -- cgit 1.3.0-6-gf8a5