Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd locationSiteKeyCache and use for siteUtil.isBookmarked #8894
Conversation
|
|
||
| /** | ||
| * Checks if a siteDetail has the specified tag. | ||
| * O(n) warning; this iterates through sites. |
This comment has been minimized.
This comment has been minimized.
bbondy
May 17, 2017
Member
I think this should either be removed or it should just access in O(1) to check via site key.
| const site = sites.get(key) | ||
| if (!site) { | ||
| return false | ||
| } |
This comment has been minimized.
This comment has been minimized.
bbondy
May 17, 2017
Member
some will still iterate over everything, I think it would be best to just make the cache related to bookmarks, and if the key is in there then return in O(1) if it is bookmarked.
This comment has been minimized.
This comment has been minimized.
ayumi
May 17, 2017
Author
Contributor
This should only iterate over a median of 1 or 2 keys.
We could have a location-to-bookmarked cache if we assume a location can be bookmarked only once.
This comment has been minimized.
This comment has been minimized.
| } | ||
| const bookmarked = isLocationBookmarked(state, url) | ||
| tabValue = tabValue.set('bookmarked', bookmarked) | ||
| state = tabState.updateTabValue(state, tabValue) |
This comment has been minimized.
This comment has been minimized.
bbondy
May 17, 2017
Member
I think this should all be removed and then just add the bookmarked property in getTabValue and it'll work better.
This comment has been minimized.
This comment has been minimized.
ayumi
May 17, 2017
Author
Contributor
bookmarking a page doesn't seem to trigger this function. how would that state change get reflected here?
This comment has been minimized.
This comment has been minimized.
bbondy
May 18, 2017
•
Member
I think I'd handle appConstants.APP_ADD_SITE in the tabsReducer, the only problem is that doesn't tell you which tab to update. You could either find the tabs with that location or pass in the info with ADD_SITE, that might be better if you can fix all the callers.
Then you could just callupdateTab after getting the tab by tabId in tabs.js
fecb5d3
to
ffe78cf
| @@ -96,6 +96,7 @@ class NewTabPage extends React.Component { | |||
| }).size > 0 | |||
| } | |||
| isBookmarked (siteProps) { | |||
| // XXX: Fixme, not passing state in! | |||
This comment has been minimized.
This comment has been minimized.
bbondy
May 19, 2017
Member
Could you check how often this is called? If it is often could you put this in a different component passing in only the URL? It would ensure each is only rendered / called once.
This comment has been minimized.
This comment has been minimized.
ayumi
May 19, 2017
Author
Contributor
i think it's called once per site icon shown on newTab, when you open a new tab.
it seems to be pretty fast.
| const assert = require('assert') | ||
| const Immutable = require('immutable') | ||
| // const mockery = require('mockery') | ||
| // const settings = require('../../../js/constants/settings') |
This comment has been minimized.
This comment has been minimized.
| // const mockery = require('mockery') | ||
| // const settings = require('../../../js/constants/settings') | ||
|
|
||
| describe('siteCache', function () { |
This comment has been minimized.
This comment has been minimized.
| const siteUtil = require('./siteUtil') | ||
| const UrlUtil = require('../lib/urlutil') | ||
|
|
||
| const createLocationSiteKeysCache = (state) => { |
This comment has been minimized.
This comment has been minimized.
bbondy
May 19, 2017
Member
In a follow up after this is merged, please move this to app/common/state. Basically no files should be in js/* anymore and we're migrating away from that.
| @@ -0,0 +1,145 @@ | |||
| /* global describe, it */ | |||
This comment has been minimized.
This comment has been minimized.
|
Some minor follow ups to do in a new commit but merging this. |
Add locationSiteKeyCache and use for siteUtil.isBookmarked
ayumi commentedMay 16, 2017
•
edited
Fix #8703
Submitter Checklist:
git rebase -ito squash commits (if needed).Test Plan:
Reviewer Checklist:
Tests