« get me outta code hell

data: artist: combine artistData with artistAliasData - 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>2024-01-30 10:50:47 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-30 14:30:05 -0400
commitf12bbec38694c30a79655a0be54768cd83f1efb5 (patch)
treee002a7784069f9bded34f81006fde798c1224979 /src
parentfbf452ff1283b79ab5c4428ca6ccb13713ae9107 (diff)
data: artist: combine artistData with artistAliasData
Diffstat (limited to 'src')
-rw-r--r--src/data/things/artist.js44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/data/things/artist.js b/src/data/things/artist.js
index 5e12f389..a12dc963 100644
--- a/src/data/things/artist.js
+++ b/src/data/things/artist.js
@@ -6,7 +6,7 @@ import CacheableObject from '#cacheable-object';
 import {colors} from '#cli';
 import {input} from '#composite';
 import find from '#find';
-import {unique} from '#sugar';
+import {stitchArrays, unique} from '#sugar';
 import Thing from '#thing';
 import {isName, validateArrayItems} from '#validators';
 import {sortAlphabetically} from '#wiki-data';
@@ -276,26 +276,34 @@ export class Artist extends Thing {
     documentThing: Artist,
 
     save(results) {
-      const artistData = results;
-
-      const artistAliasData = results.flatMap((artist) => {
-        const origRef = Thing.getReference(artist);
-        return artist.aliasNames?.map((name) => {
-          const alias = new Artist();
-          alias.name = name;
-          alias.isAlias = true;
-          alias.aliasedArtist = origRef;
-          alias.artistData = artistData;
-          return alias;
-        }) ?? [];
-      });
-
-      return {artistData, artistAliasData};
+      const artists = results;
+
+      const artistRefs =
+        artists.map(artist => Thing.getReference(artist));
+
+      const artistAliasNames =
+        artists.map(artist => artist.aliasNames);
+
+      const artistAliases =
+        stitchArrays({
+          originalArtistRef: artistRefs,
+          aliasNames: artistAliasNames,
+        }).flatMap(({originalArtistRef, aliasNames}) =>
+            aliasNames.map(name => {
+              const alias = new Artist();
+              alias.name = name;
+              alias.isAlias = true;
+              alias.aliasedArtist = originalArtistRef;
+              return alias;
+            }));
+
+      const artistData = [...artists, ...artistAliases];
+
+      return {artistData};
     },
 
-    sort({artistData, artistAliasData}) {
+    sort({artistData}) {
       sortAlphabetically(artistData);
-      sortAlphabetically(artistAliasData);
     },
   });