-
Notifications
You must be signed in to change notification settings - Fork 79
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
Fix duplicate pages in on this day results. #937
Fix duplicate pages in on this day results. #937
Conversation
The `events` for the following days are examples having dupe pages: `onthisday/events/09/14` "Telecommunications companies MCI Communications and WorldCom complete their $37 billion merger to form MCI WorldCom." `onthisday/events/09/01` "St. Petersburg, Russia, changes its name to Petrograd." Bug: T175974
v1/onthisday.js
Outdated
@@ -26,7 +26,23 @@ class Feed extends BaseFeed { | |||
[req.params.type]: res.body[req.params.type] | |||
}; | |||
} | |||
return super._hydrateResponse(hyper, req, res); | |||
const hydratedResponse = super._hydrateResponse(hyper, req, res); |
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.
It's actually faster to use Objects to determine whether a value should be filtered out:
return super._hydrateResponse(hyper, req, res).then((response) => {
Object.keys(response.body).forEach((key) => {
if (!Array.isArray(response.body[key])) {
return;
}
response.body[key].forEach((elem) => {
if (!elem || !Array.isArray(elem.pages)) {
return;
}
const titles = {};
elem.pages = elem.pages.filter((item) => {
if (titles[item.title]) {
return false;
}
titles[item.title] = true;
return true;
});
});
});
return response;
});
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.
@d00rman
Updated! I kept the declarative naming, but I don't feel super strongly about it if you prefer it more concise.
Quick question - the (type being either |
@montehurd Nope, because we need |
The
events
for the following days are examples having dupe pages:onthisday/events/09/14
"Telecommunications companies MCI Communications and WorldCom complete their $37 billion merger to form MCI WorldCom."
onthisday/events/09/01
"St. Petersburg, Russia, changes its name to Petrograd."
Bug: T175974