diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-01-17 16:05:50 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-01-17 16:10:19 -0400 |
commit | 65844843ebcf66935fb19b433883b35186c125be (patch) | |
tree | 1e09e463a451de54678e6b58053c976fffccddf5 | |
parent | 123a44625370e0c3ee1cdefcea8755c1e70f32d4 (diff) |
test, yaml: rework linkAndBindWikiData
-rw-r--r-- | src/data/yaml.js | 14 | ||||
-rw-r--r-- | test/lib/wiki-data.js | 27 |
2 files changed, 25 insertions, 16 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js index 819c639f..9f2bd7a4 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -1514,18 +1514,7 @@ export async function loadAndProcessDataDocuments({dataPath}) { // Data linking! Basically, provide (portions of) wikiData to the Things which // require it - they'll expose dynamically computed properties as a result (many // of which are required for page HTML generation and other expected behavior). -// -// The XXX_decacheWikiData option should be used specifically to mark -// points where you *aren't* replacing any of the arrays under wikiData with -// new values, and are using linkWikiDataArrays to instead "decache" data -// properties which depend on any of them. It's currently not possible for -// a CacheableObject to depend directly on the value of a property exposed -// on some other CacheableObject, so when those values change, you have to -// manually decache before the object will realize its cache isn't valid -// anymore. -export function linkWikiDataArrays(wikiData, { - XXX_decacheWikiData = false, -} = {}) { +export function linkWikiDataArrays(wikiData) { const linkWikiDataSpec = new Map([ [wikiData.albumData, [ 'artTagData', @@ -1588,7 +1577,6 @@ export function linkWikiDataArrays(wikiData, { if (thing === undefined) continue; for (const key of keys) { if (!(key in wikiData)) continue; - if (XXX_decacheWikiData) thing[key] = []; thing[key] = wikiData[key]; } } diff --git a/test/lib/wiki-data.js b/test/lib/wiki-data.js index 5433de29..d2d860ce 100644 --- a/test/lib/wiki-data.js +++ b/test/lib/wiki-data.js @@ -1,12 +1,17 @@ import CacheableObject from '#cacheable-object'; import find from '#find'; +import {withEntries} from '#sugar'; import {linkWikiDataArrays} from '#yaml'; export function linkAndBindWikiData(wikiData, { inferAlbumsOwnTrackData = true, } = {}) { - function customLinkWikiDataArrays(...args) { - linkWikiDataArrays(...args); + function customLinkWikiDataArrays(wikiData, options = {}) { + linkWikiDataArrays( + (options.XXX_decacheWikiData + ? withEntries(wikiData, entries => entries + .map(([key, value]) => [key, value.slice()])) + : wikiData)); // If albumData is present, automatically set albums' ownTrackData values // by resolving track sections' references against the full array. This is @@ -43,7 +48,23 @@ export function linkAndBindWikiData(wikiData, { // Use this if you HAVEN'T mutated wikiData and just need to decache // indirect dependencies on exposed properties of other data objects. - // See documentation on linkWikiDataArarys (in yaml.js) for more info. + // + // XXX_decacheWikiData option should be used specifically to mark points + // where you *aren't* replacing any of the arrays under wikiData with + // new values, and are using linkWikiDataArrays to instead "decache" data + // properties which depend on any of them. It's currently not possible for + // a CacheableObject to depend directly on the value of a property exposed + // on some other CacheableObject, so when those values change, you have to + // manually decache before the object will realize its cache isn't valid + // anymore. + // + // The previous implementation for this involved overwriting the relevant + // wikiData properties with null, then replacing it with the original + // array, which effectively cleared a CacheableObject cache. But it isn't + // enough to clear other caches that depend on the identity of wikiData + // arrays, such as withReverseReferenceList, so now it replaces with fresh + // copies of the data arrays instead; the original identities don't get + // reused. XXX_decacheWikiData: customLinkWikiDataArrays .bind(null, wikiData, {XXX_decacheWikiData: true}), |