Skip to content
This repository has been archived by the owner. It is now read-only.

Add locationSiteKeyCache and use for siteUtil.isBookmarked #8894

Merged
merged 1 commit into from May 19, 2017

Conversation

@ayumi
Copy link
Contributor

ayumi commented May 16, 2017

Fix #8703

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).

Test Plan:

  • Make sure tests are passing.

Reviewer Checklist:

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header
@ayumi ayumi force-pushed the fix/url-bar-is-bookmarked-cache branch from 916bb43 to 1584019 May 17, 2017

/**
* Checks if a siteDetail has the specified tag.
* O(n) warning; this iterates through sites.

This comment has been minimized.

Copy link
@bbondy

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.

Copy link
@bbondy

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.

Copy link
@ayumi

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.

Copy link
@bbondy

bbondy May 18, 2017

Member

gotcha ok

}
const bookmarked = isLocationBookmarked(state, url)
tabValue = tabValue.set('bookmarked', bookmarked)
state = tabState.updateTabValue(state, tabValue)

This comment has been minimized.

Copy link
@bbondy

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.

Copy link
@ayumi

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.

Copy link
@bbondy

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

@ayumi ayumi force-pushed the fix/url-bar-is-bookmarked-cache branch 6 times, most recently from fecb5d3 to ffe78cf May 18, 2017
Fix #8703
@ayumi ayumi force-pushed the fix/url-bar-is-bookmarked-cache branch from ffe78cf to 980a855 May 19, 2017
@@ -96,6 +96,7 @@ class NewTabPage extends React.Component {
}).size > 0
}
isBookmarked (siteProps) {
// XXX: Fixme, not passing state in!

This comment has been minimized.

Copy link
@bbondy

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.

Copy link
@ayumi

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.

Copy link
@bbondy

bbondy May 19, 2017

Member

nit: these can be removed in a follow up

// const mockery = require('mockery')
// const settings = require('../../../js/constants/settings')

describe('siteCache', function () {

This comment has been minimized.

Copy link
@bbondy

bbondy May 19, 2017

Member

nice job on these tests 💯

const siteUtil = require('./siteUtil')
const UrlUtil = require('../lib/urlutil')

const createLocationSiteKeysCache = (state) => {

This comment has been minimized.

Copy link
@bbondy

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.

Copy link
@bbondy

bbondy May 19, 2017

Member

Please also move this test to test/unit/app/common/state/

@bbondy
Copy link
Member

bbondy commented May 19, 2017

Some minor follow ups to do in a new commit but merging this.

@bbondy bbondy merged commit 5fc6f05 into master May 19, 2017
0 of 2 checks passed
0 of 2 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build failed
Details
bbondy added a commit that referenced this pull request May 19, 2017
Add locationSiteKeyCache and use for siteUtil.isBookmarked
@luixxiul luixxiul added this to the 0.15.300 milestone May 19, 2017
ayumi added a commit that referenced this pull request May 19, 2017
Auditors: @bbondy

Test Plan:
Check that automated tests pass.
@ayumi ayumi mentioned this pull request May 19, 2017
0 of 7 tasks complete
bbondy added a commit that referenced this pull request May 19, 2017
Address feedback in PR #8894
bbondy added a commit that referenced this pull request May 19, 2017
Address feedback in PR #8894
@bsclifton bsclifton deleted the fix/url-bar-is-bookmarked-cache branch May 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.