diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-11-05 19:13:09 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-11-05 19:13:09 -0400 |
commit | 3baba32aacebe09314fa7609817c7d3cc9e6ac7b (patch) | |
tree | 496cd9a6185205c8f7d251f0db284b14c00a92f6 /src/find.js | |
parent | 1704fa016ba81318e92ef59951f4a9b3ffc4d091 (diff) | |
parent | 7841f97cde6182359bb3f2b0f6117c6379ef18dc (diff) |
Merge branch 'fast-find-track' into preview
Diffstat (limited to 'src/find.js')
-rw-r--r-- | src/find.js | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/find.js b/src/find.js index 8c9413b7..dfcaa9aa 100644 --- a/src/find.js +++ b/src/find.js @@ -2,6 +2,7 @@ import {inspect} from 'node:util'; import {colors, logWarn} from '#cli'; import {typeAppearance} from '#sugar'; +import {CacheableObject} from '#things'; function warnOrThrow(mode, message) { if (mode === 'error') { @@ -16,6 +17,8 @@ function warnOrThrow(mode, message) { } export function processAllAvailableMatches(data, { + include = thing => true, + getMatchableNames = thing => (Object.hasOwn(thing, 'name') ? [thing.name] @@ -26,6 +29,10 @@ export function processAllAvailableMatches(data, { const multipleNameMatches = Object.create(null); for (const thing of data) { + if (!include(thing)) continue; + + byDirectory[thing.directory] = thing; + for (const name of getMatchableNames(thing)) { if (typeof name !== 'string') { logWarn`Unexpected ${typeAppearance(name)} returned in names for ${inspect(thing)}`; @@ -33,6 +40,7 @@ export function processAllAvailableMatches(data, { } const normalizedName = name.toLowerCase(); + if (normalizedName in byName) { const alreadyMatchesByName = byName[normalizedName]; byName[normalizedName] = null; @@ -45,8 +53,6 @@ export function processAllAvailableMatches(data, { byName[normalizedName] = thing; } } - - byDirectory[thing.directory] = thing; } return {byName, byDirectory, multipleNameMatches}; @@ -55,6 +61,7 @@ export function processAllAvailableMatches(data, { function findHelper({ referenceTypes, + include = undefined, getMatchableNames = undefined, }) { const keyRefRegex = @@ -84,6 +91,7 @@ function findHelper({ if (!subcache) { subcache = processAllAvailableMatches(data, { + include, getMatchableNames, }); @@ -178,6 +186,22 @@ const find = { ? [] : [track.name]), }), + + trackOriginalReleasesOnly: findHelper({ + referenceTypes: ['track'], + + include: track => + !CacheableObject.getUpdateValue(track, 'originalReleaseTrack'), + + // It's still necessary to check alwaysReferenceByDirectory here, since it + // may be set manually (with the `Always Reference By Directory` field), and + // these shouldn't be matched by name (as per usual). See the definition for + // that property for more information. + getMatchableNames: track => + (track.alwaysReferenceByDirectory + ? [] + : [track.name]), + }), }; export default find; @@ -200,6 +224,7 @@ export function bindFind(wikiData, opts1) { newsEntry: 'newsData', staticPage: 'staticPageData', track: 'trackData', + trackOriginalReleasesOnly: 'trackData', }).map(([key, value]) => { const findFn = find[key]; const thingData = wikiData[value]; |