« get me outta code hell

search: factor out call to bindSearchUtilities(), at least - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-10-08 21:01:22 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-10-08 21:01:22 -0300
commit41047053455418f274d73bbce43ab4235601e78e (patch)
tree4921fed145c1bb30d356f5398a2b386b6426d81c
parentcba6ff9c72edb8a5cf2a933be6b8d8e8ef85a040 (diff)
search: factor out call to bindSearchUtilities(), at least
-rw-r--r--src/search.js24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/search.js b/src/search.js
index c853c3be..138a2d2c 100644
--- a/src/search.js
+++ b/src/search.js
@@ -39,16 +39,13 @@ function bindSearchUtilities({
   return bound;
 }
 
-function populateSearchIndex(index, descriptor, opts) {
-  const {wikiData} = opts;
-  const bound = bindSearchUtilities(opts);
-
+function populateSearchIndex(index, descriptor, wikiData, utilities) {
   for (const thing of descriptor.select(wikiData)) {
     const reference = thing.constructor.getReference(thing);
 
     let processed;
     try {
-      processed = descriptor.process(thing, bound);
+      processed = descriptor.process(thing, utilities);
     } catch (caughtError) {
       throw new Error(
         `Failed to process searchable thing ${reference}`,
@@ -105,17 +102,20 @@ export async function writeSearchData({
       .map(descriptor =>
         makeSearchIndex(descriptor, {FlexSearch}));
 
+  const utilities =
+    bindSearchUtilities({
+      checkIfImagePathHasCachedThumbnails,
+      getThumbnailEqualOrSmaller,
+      thumbsCache,
+      urls,
+      wikiData,
+    });
+
   stitchArrays({
     index: indexes,
     descriptor: descriptors,
   }).forEach(({index, descriptor}) =>
-      populateSearchIndex(index, descriptor, {
-        checkIfImagePathHasCachedThumbnails,
-        getThumbnailEqualOrSmaller,
-        thumbsCache,
-        urls,
-        wikiData,
-      }));
+      populateSearchIndex(index, descriptor, wikiData, utilities));
 
   const serializedIndexes =
     await Promise.all(indexes.map(serializeIndex));