« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/file-size-preloader.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/file-size-preloader.js')
-rw-r--r--src/file-size-preloader.js24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/file-size-preloader.js b/src/file-size-preloader.js
index 5eff243a..b2a55407 100644
--- a/src/file-size-preloader.js
+++ b/src/file-size-preloader.js
@@ -18,10 +18,10 @@
 // are very, very fast.
 
 import {stat} from 'node:fs/promises';
-import {relative, resolve} from 'node:path';
+import {relative, resolve, sep} from 'node:path';
 
 import {logWarn} from '#cli';
-import {transposeArrays} from '#sugar';
+import {filterMultipleArrays, transposeArrays} from '#sugar';
 
 export default class FileSizePreloader {
   #paths = [];
@@ -125,17 +125,29 @@ export default class FileSizePreloader {
         this.#sizes.slice(0, this.#loadedPathIndex),
       ]);
 
+    // Do not be alarmed: This cannot be meaningfully moved to
+    // the top because stringifyCache sorts alphabetically lol
+    entries.push(['_separator', sep]);
+
     return Object.fromEntries(entries);
   }
 
   loadFromCache(cache) {
-    const entries =
-      Object.entries(cache)
-        .filter(([p]) => !this.#paths.includes(p));
-
+    const {_separator: cacheSep, ...rest} = cache;
+    const entries = Object.entries(rest);
     let [newPaths, newSizes] = transposeArrays(entries);
+
+    if (sep !== cacheSep) {
+      newPaths = newPaths.map(p => p.split(cacheSep).join(sep));
+    }
+
     newPaths = newPaths.map(p => resolve(this.prefix, p));
 
+    filterMultipleArrays(
+      newPaths,
+      newSizes,
+      path => !this.#paths.includes(path));
+
     this.#paths.splice(this.#loadedPathIndex + 1, 0, ...newPaths);
     this.#sizes.splice(this.#loadedPathIndex + 1, 0, ...newSizes);
     this.#loadedPathIndex += entries.length;