Skip to content
This repository has been archived by the owner on Dec 11, 2019. 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 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


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

Choose a reason for hiding this comment

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

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
}
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

gotcha ok

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

Choose a reason for hiding this comment

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

I think this should all be removed and then just add the bookmarked property in getTabValue and it'll work better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bookmarking a page doesn't seem to trigger this function. how would that state change get reflected here?

Copy link
Member

@bbondy bbondy May 18, 2017

Choose a reason for hiding this comment

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

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 Compare May 19, 2017 00:05
@ayumi ayumi force-pushed the fix/url-bar-is-bookmarked-cache branch from ffe78cf to 980a855 Compare May 19, 2017 00:14
@@ -96,6 +96,7 @@ class NewTabPage extends React.Component {
}).size > 0
}
isBookmarked (siteProps) {
// XXX: Fixme, not passing state in!
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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')
Copy link
Member

@bbondy bbondy May 19, 2017

Choose a reason for hiding this comment

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

nit: these can be removed in a follow up

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

describe('siteCache', function () {
Copy link
Member

Choose a reason for hiding this comment

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

nice job on these tests 💯

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

const createLocationSiteKeysCache = (state) => {
Copy link
Member

Choose a reason for hiding this comment

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

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 */
Copy link
Member

Choose a reason for hiding this comment

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

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
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
7 tasks
bbondy added a commit that referenced this pull request May 19, 2017
bbondy added a commit that referenced this pull request May 19, 2017
@bsclifton bsclifton deleted the fix/url-bar-is-bookmarked-cache branch May 22, 2017 16:39
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.

3 participants