Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort reverse reference lists by date, in data #536

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions src/data/composite/wiki-data/withReverseContributionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -129,16 +130,19 @@ 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, {
['#cacheRecord']: cacheRecord,
['#referencingThings']: referencingThings,
['#referencedThings']: referencedThings,
}) => {
const allReferencedThings = new Set();

stitchArrays({
referencingThing: referencingThings,
referencedThings: referencedThings,
Expand All @@ -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();
},
},
Expand Down
36 changes: 33 additions & 3 deletions src/data/composite/wiki-data/withReverseReferenceList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -128,16 +129,19 @@ 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, {
['#cacheRecord']: cacheRecord,
['#referencingThings']: referencingThings,
['#referencedThings']: referencedThings,
}) => {
const allReferencedThings = new Set();

stitchArrays({
referencingThing: referencingThings,
referencedThings: referencedThings,
Expand All @@ -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();
},
},
Expand Down