-
-
Notifications
You must be signed in to change notification settings - Fork 42
fix for duplicate documents sharing the same ID #552
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,3 @@ | ||
| module.exports = {}; | ||
|
|
||
| var hasName = function(r) { | ||
| return r.name; | ||
| }; | ||
|
|
||
| var isDefined = function(r) { | ||
| return r; | ||
| }; | ||
|
|
||
| /* | ||
| This function finds all the WOF records associated with a hierarchy | ||
|
|
||
|
|
@@ -26,24 +16,20 @@ var isDefined = function(r) { | |
| ] | ||
|
|
||
| lastly, filter out any hierarchy elements that are undefined or w/o a name | ||
|
|
||
| */ | ||
| function resolveHierarchy(wofRecords, hierarchy) { | ||
| return Object.keys(hierarchy).map(function(key) { | ||
| return wofRecords[hierarchy[key]]; | ||
| }).filter(isDefined).filter(hasName); | ||
| } | ||
|
|
||
| /* | ||
| This function returns all the resolved hierarchies for a wofRecord. Each | ||
| wofRecord can have multiple hierarchies, so resolve them by looking up the | ||
| referenced wofRecord in the big collection of wofRecords. | ||
| referenced wofRecord in the big collection of parentRecords. | ||
| */ | ||
| module.exports = function(wofRecords) { | ||
| return function(wofRecord) { | ||
| return wofRecord.hierarchies.reduce(function(resolvedHierarchies, hierarchy) { | ||
| resolvedHierarchies.push(resolveHierarchy(wofRecords, hierarchy)); | ||
| return resolvedHierarchies; | ||
| }, []); | ||
| module.exports = (parentRecords) => { | ||
| return (wofRecord) => { | ||
| return wofRecord.hierarchies.map(hierarchy => { | ||
| return Object.values(hierarchy) | ||
| .map(parentId => parentRecords[parentId]) | ||
| .filter(Boolean) | ||
| .filter(r => r.name); | ||
| }); | ||
|
Comment on lines
+26
to
+33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice cleanup here. Modern JS and easier to understand as well. |
||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,18 +151,16 @@ function setupDocument(record, hierarchy) { | |
|
|
||
| } | ||
|
|
||
| module.exports.create = function(hierarchy_finder) { | ||
| return through2.obj(function(record, enc, next) { | ||
| // if there are no hierarchies, then just return the doc as-is | ||
| var hierarchies = hierarchy_finder(record); | ||
| module.exports.create = (hierarchy_finder) => { | ||
| return through2.obj(function(record, _enc, next) { | ||
| const hierarchies = hierarchy_finder(record); | ||
|
|
||
| try { | ||
| if (hierarchies && hierarchies.length > 0) { | ||
| hierarchies.forEach(function(hierarchy) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the major change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I verified via a |
||
| this.push(setupDocument(record, hierarchy)); | ||
| }, this); | ||
|
|
||
| if (Array.isArray(hierarchies) && hierarchies.length > 0) { | ||
| // only use the first hierarchy when multiple hierarchies exist | ||
| this.push(setupDocument(record, hierarchies[0])); | ||
| } else { | ||
| // if there are no hierarchies, then just return the doc as-is | ||
| this.push(setupDocument(record)); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is excessive even by @trescube standards 😆