Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Issue #8690: Specify the frecency threshold for the fetched top frecent sites #8806

Merged
merged 2 commits into from
Jan 26, 2021

Conversation

gabrielluong
Copy link
Member

Fixes #8690. Requires AS bump with mozilla/application-services#3645.

Pull Request checklist

  • Quality: This PR builds and passes detekt/ktlint checks (A pre-push hook is recommended)
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry or does not need one
  • Accessibility: The code in this PR follows accessibility best practices or does not include any user facing features

After merge

  • Milestone: Make sure issues closed by this pull request are added to the milestone of the version currently in development.
  • Breaking Changes: If this is a breaking change, please push a draft PR on Reference Browser to address the breaking issues.

@gabrielluong gabrielluong added the a-s Application Services work needed label Oct 27, 2020
@gabrielluong gabrielluong force-pushed the frecency branch 2 times, most recently from 3a96f27 to 2d07c10 Compare October 27, 2020 04:49
@mergify
Copy link
Contributor

mergify bot commented Oct 27, 2020

This pull request has conflicts when rebasing. Could you fix it @gabrielluong? 🙏

@@ -67,7 +68,8 @@ class DefaultTopSitesStorage(

override suspend fun getTopSites(
totalSites: Int,
includeFrecent: Boolean
includeFrecent: Boolean,
frecencyThreshold: FrecencyThresholdOption
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this option change? Maybe just put it in the constructor or leave it internal as part of our implicit feature expectations.

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't change, but we also fetch the option from the TopSiteConfig

@gabrielluong gabrielluong requested a review from a team as a code owner October 29, 2020 00:49
@gabrielluong gabrielluong added 🕵️‍♀️ needs review PRs that need to be reviewed and removed a-s Application Services work needed labels Oct 29, 2020
Copy link
Contributor

@grigoryk grigoryk left a comment

Choose a reason for hiding this comment

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

Overall this looks good! I think we should simplify the APIs a bit to avoid having illegal combinations around, and make sure to separately test the a-s bump (I'd prefer that in a separate PR, actually).

@mergify
Copy link
Contributor

mergify bot commented Nov 5, 2020

This pull request has conflicts when rebasing. Could you fix it @gabrielluong? 🙏

@mergify
Copy link
Contributor

mergify bot commented Nov 6, 2020

This pull request has conflicts when rebasing. Could you fix it @gabrielluong? 🙏

Copy link
Contributor

@grigoryk grigoryk left a comment

Choose a reason for hiding this comment

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

Looks good! Just some nits and random musings.

🚢🚢🚢

@grigoryk
Copy link
Contributor

grigoryk commented Nov 9, 2020

@gabrielluong i'll do a round of testing for the a-s version bump before we land this.

@mergify
Copy link
Contributor

mergify bot commented Nov 11, 2020

This pull request has conflicts when rebasing. Could you fix it @gabrielluong? 🙏

@mergify
Copy link
Contributor

mergify bot commented Nov 16, 2020

This pull request has conflicts when rebasing. Could you fix it @gabrielluong? 🙏

@mergify
Copy link
Contributor

mergify bot commented Nov 17, 2020

This pull request has conflicts when rebasing. Could you fix it @gabrielluong? 🙏

assertEquals(5, infos.size)
assertEquals("https://www.mozilla.com/foo/bar/baz", infos[0].url)
assertEquals("https://www.example.com/123", infos[1].url)
assertEquals("https://news.ycombinator.com/", infos[2].url)
assertEquals("https://mozilla.com/a1/b2/c3", infos[3].url)
assertEquals("https://www.example.com/12345", infos[4].url)

infos = history.getTopFrecentSites(100, frecencyThreshold = FrecencyThresholdOption.SKIP_ONE_TIME_PAGES)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will it work with negative values? e.g. history.getTopFrecentSites(-4, frecencyThreshold = FrecencyThresholdOption.NONE)

Textbook unit test :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I added

if (numItems <= 0) {
   return emptyList()
}

but I am wondering if we would prefer doing a require(numItems >= 0)

@@ -213,15 +215,15 @@ class DefaultTopSitesStorageTest {

val frecentSite2 = TopFrecentSiteInfo("https://example.com", "Example")
val frecentSite3 = TopFrecentSiteInfo("https://getpocket.com", "Pocket")
whenever(historyStorage.getTopFrecentSites(anyInt())).thenReturn(
whenever(historyStorage.getTopFrecentSites(anyInt(), any())).thenReturn(
Copy link
Contributor

Choose a reason for hiding this comment

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

I really recommend doing away with the mocks, and just using the real storage implementation instead. It's a little bit more working setting things up, but really not much more - you'd need to actually insert history items and visits yourself to prep the storage.

For an example of how to set this up, see browser-storage-sync component. Specifically, you may need to copy-paste some bits from build.gradle:

// These dependencies are part of this module's public API.
    api(Dependencies.mozilla_places) {
        // Use our own version of the Glean dependency,
        // which might be different from the version declared by A-S.
        exclude group: 'org.mozilla.components', module: 'service-glean'
    }
...
testImplementation Dependencies.mozilla_places
testImplementation Dependencies.mozilla_full_megazord_forUnitTests
testImplementation Dependencies.mozilla_glean_forUnitTests
...

(it may work without the glean stuff, try that first; i don't recall the details right now)

The result should be a much more robust and useful test suite which exercises our whole stack! This will become a good integration test, instead of a "we're calling the right APIs" unit test. The latter is helpful, but the former actually gives you confidence that the system is working correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

I spent some time on this, but ran into some issues that I have not managed to figure out yet. I will spin this task into a new issue #9501 to not block this any further.

@mergify
Copy link
Contributor

mergify bot commented Jan 7, 2021

This pull request has conflicts when rebasing. Could you fix it @gabrielluong? 🙏

@codecov
Copy link

codecov bot commented Jan 25, 2021

Codecov Report

Merging #8806 (bca8f9b) into master (813db1d) will decrease coverage by 2.81%.
The diff coverage is 69.23%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #8806      +/-   ##
============================================
- Coverage     74.57%   71.75%   -2.82%     
+ Complexity     5958     1957    -4001     
============================================
  Files           811      313     -498     
  Lines         29606     9662   -19944     
  Branches       4882     1630    -3252     
============================================
- Hits          22078     6933   -15145     
+ Misses         5055     1908    -3147     
+ Partials       2473      821    -1652     
Impacted Files Coverage Δ Complexity Δ
...s/browser/storage/memory/InMemoryHistoryStorage.kt 84.50% <ø> (ø) 28.00 <0.00> (ø)
...lla/components/feature/top/sites/TopSitesConfig.kt 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...la/components/feature/top/sites/TopSitesStorage.kt 0.00% <ø> (ø) 0.00 <0.00> (ø)
...re/top/sites/presenter/DefaultTopSitesPresenter.kt 53.33% <0.00%> (-8.21%) 6.00 <0.00> (ø)
...nents/browser/storage/sync/PlacesHistoryStorage.kt 69.23% <100.00%> (ø) 24.00 <2.00> (+1.00)
...a/mozilla/components/browser/storage/sync/Types.kt 80.43% <100.00%> (+1.36%) 0.00 <0.00> (ø)
...onents/feature/top/sites/DefaultTopSitesStorage.kt 70.27% <100.00%> (ø) 12.00 <0.00> (ø)
...in/java/mozilla/components/lib/jexl/lexer/Token.kt
...components/feature/accounts/push/SendTabFeature.kt
.../components/browser/engine/system/NestedWebView.kt
... and 496 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 813db1d...dd3a69e. Read the comment docs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🛬 needs landing PRs that are ready to land 🕵️‍♀️ needs review PRs that need to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow TopSitesConfig to specify the frecency threshold
3 participants