« get me outta code hell

data: withAlwaysReferenceByDirectory: micro-optimizations - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-11-05 17:52:25 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-05 18:32:48 -0400
commitd6672865a59a94a2acdd3ec7e827f96f8c3e67e4 (patch)
tree64dbb93af6aa3f38b94a5e274a4032528c7c1265 /src
parent0175df41994ed44d2dded79ac21badf463140e14 (diff)
data: withAlwaysReferenceByDirectory: micro-optimizations
Diffstat (limited to 'src')
-rw-r--r--src/data/composite/things/track/withAlwaysReferenceByDirectory.js29
1 files changed, 19 insertions, 10 deletions
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({