« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/data')
-rw-r--r--src/data/cacheable-object.js24
-rw-r--r--src/data/things.js4
2 files changed, 26 insertions, 2 deletions
diff --git a/src/data/cacheable-object.js b/src/data/cacheable-object.js
index fe1817f6..688d8a0f 100644
--- a/src/data/cacheable-object.js
+++ b/src/data/cacheable-object.js
@@ -315,6 +315,30 @@ export default class CacheableObject {
     };
   }
 
+  static cacheAllExposedProperties(obj) {
+    if (!(obj instanceof CacheableObject)) {
+      console.warn('Not a CacheableObject:', obj);
+      return;
+    }
+
+    if (!obj.constructor.propertyDescriptors) {
+      console.warn('Missing property descriptors:', obj);
+      return;
+    }
+
+    for (const [property, descriptor] of Object.entries(
+      obj.constructor.propertyDescriptors
+    )) {
+      const {flags} = descriptor;
+
+      if (!flags.expose) {
+        continue;
+      }
+
+      obj[property];
+    }
+  }
+
   static DEBUG_SLOW_TRACK_INVALID_PROPERTIES = false;
   static _invalidAccesses = new Set();
 
diff --git a/src/data/things.js b/src/data/things.js
index fa7a8d54..45cd7f2e 100644
--- a/src/data/things.js
+++ b/src/data/things.js
@@ -1071,7 +1071,7 @@ Artist.propertyDescriptors = {
       dependencies: ['trackData'],
 
       compute: ({trackData, [Artist.instance]: artist}) =>
-        trackData.filter(({commentatorArtists}) =>
+        trackData?.filter(({commentatorArtists}) =>
           commentatorArtists?.includes(artist)
         ),
     },
@@ -1098,7 +1098,7 @@ Artist.propertyDescriptors = {
       dependencies: ['albumData'],
 
       compute: ({albumData, [Artist.instance]: artist}) =>
-        albumData.filter(({commentatorArtists}) =>
+        albumData?.filter(({commentatorArtists}) =>
           commentatorArtists?.includes(artist)
         ),
     },