Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

fix(systemaddon): Dedupe Topsites #2987

Merged
merged 10 commits into from
Aug 1, 2017

Conversation

piatra
Copy link
Contributor

@piatra piatra commented Jul 27, 2017

Fixes #2933
Dedupe happens in the Feeds. I've added the hostname key to the site objects because it is displayed in the cards. Previously the value returned by shortURL was named title (especially in the tests) it but made it confusing since websites already have a title.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.407% when pulling 4e61a9f on piatra:bug-2933-dedupe-topsites into 929fc6a on mozilla:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.407% when pulling 14969df on piatra:bug-2933-dedupe-topsites into 929fc6a on mozilla:master.

Copy link
Contributor

@k88hudson k88hudson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks great, I'm a bit worried about a particular case though; if we end up with <12 items due to deduping, won't that result in a lot of extra querying because the check for if we have enough sites will return false (and always return false until the sites change). Can we do something to prevent that from happening?

// Parse site url and extract hostname.
pinned.forEach(site => { site.hostname = shortURL(site); });

return this.dedupe.collection(pinned).slice(0, TOP_SITES_SHOWMORE_LENGTH);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this always favour the pinned item? Or is there a possibility it would get removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently no, but Dedupe can be called with a compare function that prefers pinned items.

}

/**
* Removes duplicates in a list based on createKey.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably say it picks the first item that it finds. So re: @k88hudson's question about pinned, it will remove the pinned if a non-pinned duplicate key item appeared first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, nevermind. it depends on the compare.

@piatra
Copy link
Contributor Author

piatra commented Jul 31, 2017

@k88hudson If I'm reading this right we are already calling this.refresh every time until the user has 12 non default topsites (so a lot for new profiles). Is there any reason we don't just have the 15 minutes rule?

@piatra
Copy link
Contributor Author

piatra commented Jul 31, 2017

We could also, after getting this result, compare the length of the result with the length of this.store.getState().TopSites.rows if it's the same we can return early.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.407% when pulling 5fad94b on piatra:bug-2933-dedupe-topsites into 729f4c6 on mozilla:master.

return site.hostname;
}
_dedupeCompare(storedValue, newValue) {
return newValue.isPinned;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we want to somehow indicate if both are pinned and neither deduped?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I'm currently working on, realized just as I wanted to request review.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.407% when pulling 1defd7a on piatra:bug-2933-dedupe-topsites into 1b4406c on mozilla:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.407% when pulling 8ba908a on piatra:bug-2933-dedupe-topsites into 1b4406c on mozilla:master.

Copy link
Contributor

@k88hudson k88hudson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great, just one thing that seems to crash Top Sites

const result = [];
groups.forEach(values => {
const valueMap = new Map();
values.forEach(value => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

firefox style usually prefers for (const value of values) because there is slightly less overhead, but feel free to do that as a follow-up

this.dedupe = new Dedupe(this._dedupeKey);
}
_dedupeKey(site) {
return site.hostname;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is throwing an error and crashing the feed when the pinned group contains null items, so maybe check site && site.hostname and/or filter out null values from pinned before running dedupe

return insertPinned([...frecent, ...DEFAULT_TOP_SITES], pinned).slice(0, TOP_SITES_SHOWMORE_LENGTH);
// Group together websites that require deduping.
const topsitesGroup = [pinned, frecent, DEFAULT_TOP_SITES];
topsitesGroup.forEach(group => group.forEach(site => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do this to filter out the null items and prevent accidental mutation?

for (const group in topsitesGroup) {
  group
    .filter(site => site)
    .map(site => Object.assign({}, site, {hostName: shortURL(site)});
}

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.407% when pulling 9027a55 on piatra:bug-2933-dedupe-topsites into 1b4406c on mozilla:master.

@k88hudson
Copy link
Contributor

🔥 🔥 🔥

@piatra piatra merged commit d782ac9 into mozilla:master Aug 1, 2017
@piatra piatra deleted the bug-2933-dedupe-topsites branch August 1, 2017 21:17
@as-pine-proxy
Copy link
Collaborator

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants