diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-06-26 12:08:04 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-06-26 12:08:04 -0300 |
commit | c28cfcaa4fe3af6f30ccc5ef3c6b4a3be91d88c0 (patch) | |
tree | 068f80c4e33127d7983226a72022e85ad81d33c5 | |
parent | 8c545a135943d47f9ceb6a271874950d165b41ee (diff) |
data: withReverse{Contribution,Reference}List: sort by date
-rw-r--r-- | src/data/composite/wiki-data/withReverseContributionList.js | 36 | ||||
-rw-r--r-- | src/data/composite/wiki-data/withReverseReferenceList.js | 36 |
2 files changed, 66 insertions, 6 deletions
diff --git a/src/data/composite/wiki-data/withReverseContributionList.js b/src/data/composite/wiki-data/withReverseContributionList.js index 63e712bb..07b085c4 100644 --- a/src/data/composite/wiki-data/withReverseContributionList.js +++ b/src/data/composite/wiki-data/withReverseContributionList.js @@ -10,6 +10,7 @@ // is used, a fresh cache will always be created. import {input, templateCompositeFrom} from '#composite'; +import {sortByDate} from '#sort'; import {stitchArrays} from '#sugar'; import {exitWithoutDependency, raiseOutputWithoutDependency} @@ -129,9 +130,10 @@ export default templateCompositeFrom({ // Actually fill in the cache record. Since we're building up a *reverse* // reference list, track connections in terms of the referenced thing. - // No newly-provided dependencies here since we're mutating the cache - // record, which is properly in store and will probably be reused in the - // future (and certainly in the next step). + // Although we gather all referenced things into a set and provide that + // for sorting purposes in the next step, we *don't* reprovide the cache + // record, because we're mutating that in-place - we'll just reuse its + // existing '#cacheRecord' dependency. { dependencies: ['#cacheRecord', '#referencingThings', '#referencedThings'], compute: (continuation, { @@ -139,6 +141,8 @@ export default templateCompositeFrom({ ['#referencingThings']: referencingThings, ['#referencedThings']: referencedThings, }) => { + const allReferencedThings = new Set(); + stitchArrays({ referencingThing: referencingThings, referencedThings: referencedThings, @@ -148,10 +152,36 @@ export default templateCompositeFrom({ cacheRecord.get(referencedThing).push(referencingThing); } else { cacheRecord.set(referencedThing, [referencingThing]); + allReferencedThings.add(referencedThing); } } }); + return continuation({ + ['#allReferencedThings']: + allReferencedThings, + }); + }, + }, + + // Sort the entries in the cache records, too, just by date - the rest of + // sorting should be handled outside of withReverseContributionList, either + // preceding (changing the 'data' input) or following (sorting the output). + // Again we're mutating in place, so no need to reprovide '#cacheRecord' + // here. + { + dependencies: ['#cacheRecord', '#allReferencedThings'], + compute: (continuation, { + ['#cacheRecord']: cacheRecord, + ['#allReferencedThings']: allReferencedThings, + }) => { + for (const referencedThing of allReferencedThings) { + if (cacheRecord.has(referencedThing)) { + const referencingThings = cacheRecord.get(referencedThing); + sortByDate(referencingThings); + } + } + return continuation(); }, }, diff --git a/src/data/composite/wiki-data/withReverseReferenceList.js b/src/data/composite/wiki-data/withReverseReferenceList.js index 1f8c082f..2da9194d 100644 --- a/src/data/composite/wiki-data/withReverseReferenceList.js +++ b/src/data/composite/wiki-data/withReverseReferenceList.js @@ -12,6 +12,7 @@ // so any changes should be reflected there (until these are combined). import {input, templateCompositeFrom} from '#composite'; +import {sortByDate} from '#sort'; import {stitchArrays} from '#sugar'; import {exitWithoutDependency, raiseOutputWithoutDependency} @@ -128,9 +129,10 @@ export default templateCompositeFrom({ // Actually fill in the cache record. Since we're building up a *reverse* // reference list, track connections in terms of the referenced thing. - // No newly-provided dependencies here since we're mutating the cache - // record, which is properly in store and will probably be reused in the - // future (and certainly in the next step). + // Although we gather all referenced things into a set and provide that + // for sorting purposes in the next step, we *don't* reprovide the cache + // record, because we're mutating that in-place - we'll just reuse its + // existing '#cacheRecord' dependency. { dependencies: ['#cacheRecord', '#referencingThings', '#referencedThings'], compute: (continuation, { @@ -138,6 +140,8 @@ export default templateCompositeFrom({ ['#referencingThings']: referencingThings, ['#referencedThings']: referencedThings, }) => { + const allReferencedThings = new Set(); + stitchArrays({ referencingThing: referencingThings, referencedThings: referencedThings, @@ -147,10 +151,36 @@ export default templateCompositeFrom({ cacheRecord.get(referencedThing).push(referencingThing); } else { cacheRecord.set(referencedThing, [referencingThing]); + allReferencedThings.add(referencedThing); } } }); + return continuation({ + ['#allReferencedThings']: + allReferencedThings, + }); + }, + }, + + // Sort the entries in the cache records, too, just by date - the rest of + // sorting should be handled outside of withReverseContributionList, either + // preceding (changing the 'data' input) or following (sorting the output). + // Again we're mutating in place, so no need to reprovide '#cacheRecord' + // here. + { + dependencies: ['#cacheRecord', '#allReferencedThings'], + compute: (continuation, { + ['#cacheRecord']: cacheRecord, + ['#allReferencedThings']: allReferencedThings, + }) => { + for (const referencedThing of allReferencedThings) { + if (cacheRecord.has(referencedThing)) { + const referencingThings = cacheRecord.get(referencedThing); + sortByDate(referencingThings); + } + } + return continuation(); }, }, |