Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Move ledger data:* favicons to external files #11754

Merged
merged 1 commit into from
Dec 13, 2017
Merged

Conversation

diracdeltas
Copy link
Member

@diracdeltas diracdeltas commented Nov 1, 2017

This moves data:* favicon URLs in the ledger appState to external image files during session store cleanup. Reduces the size of my session-store-1 from ~23 MB to 5 MB.

Fix #11582

Test plan:

  1. Copy session-store-1 from a Brave profile that has had payments enabled for a while to your brave-development appData directory.
  2. Start the browser and go to about:preferences#payments. The synopsis table should appear fine.
  3. Close the browser.
  4. In your brave-development appData directory, you should now see a ledger-favicons subdirectory which contains a lot of image files. You should also notice that session-store-1 is now much smaller.
  5. Repeat step 2.

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).
  • Tagged reviewers and labelled the pull request as needed.

Test Plan:

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

@codecov-io
Copy link

codecov-io commented Nov 1, 2017

Codecov Report

Merging #11754 into master will decrease coverage by 8.74%.
The diff coverage is 21.91%.

@@            Coverage Diff             @@
##           master   #11754      +/-   ##
==========================================
- Coverage   55.09%   46.34%   -8.75%     
==========================================
  Files         275      270       -5     
  Lines       26619    25849     -770     
  Branches     4288     4116     -172     
==========================================
- Hits        14667    11981    -2686     
- Misses      11952    13868    +1916
Flag Coverage Δ
#unittest 46.34% <21.91%> (-8.75%) ⬇️
Impacted Files Coverage Δ
...erer/components/preferences/payment/ledgerTable.js 87.75% <0%> (-1.78%) ⬇️
js/about/aboutActions.js 9.09% <0%> (-0.24%) ⬇️
app/sessionStore.js 2.87% <2.04%> (-73.72%) ⬇️
js/lib/urlutil.js 86.05% <93.75%> (+0.52%) ⬆️
app/sessionStoreShutdown.js 1.26% <0%> (-85.45%) ⬇️
app/browser/reducers/windowsReducer.js 3.05% <0%> (-77.49%) ⬇️
app/browser/api/ledger.js 1.15% <0%> (-48.11%) ⬇️
app/browser/api/ledgerNotifications.js 30.26% <0%> (-44.3%) ⬇️
app/browser/windows.js 3.14% <0%> (-34.39%) ⬇️
... and 20 more

@NejcZdovc
Copy link
Contributor

@diracdeltas this is really cool. Maybe one suggestion. Now we have synopsis and about synopsis, but synopsis is parent of about synopsis. So what is in about synopsis is for sure in synopsis. If I understand this code correctly we are create all favicons twice. My suggestion would be to generate favicons for synopsis and then just assign this values to about synopsis as well. wdyt?

@NejcZdovc
Copy link
Contributor

In near future we would like to remove this duplicate entries, so that you would only have one synopsis.

)
fs.writeFile(faviconPath, parsed.data, 'base64', (err) => {
if (err) {
console.error(`Error writing file: ${faviconPath} ${err}`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

are we ok with potentially losing these?

Copy link
Member Author

@diracdeltas diracdeltas Nov 2, 2017

Choose a reason for hiding this comment

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

iirc the ledger tries to get the favicon whenever the user visits the page, so the icon would be restored on the next visit

Copy link
Contributor

Choose a reason for hiding this comment

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

@diracdeltas that's not the case. We only get favicon if there is not one

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 could add an img onerror in the synopsis table that sets the faviconURL to '' / null if the file does not exist on disk - would that cause the favicon to be re-fetched?

Copy link
Contributor

Choose a reason for hiding this comment

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

? `favicon-${index}-${Date.now()}.${parsed.ext}`
: `favicon-${index}.${parsed.ext}`
)
fs.writeFile(faviconPath, parsed.data, 'base64', (err) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

might be better to use muon.file.writeImportant

Copy link
Member Author

Choose a reason for hiding this comment

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

fs.writeFile was easier because it supported the base64 encoding parameter

try {
const basePath = getStoragePath('ledger-favicons')
const fs = require('fs')
if (!fs.existsSync(basePath)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should use the async versions of these to avoid blocking the UI thread

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 needs to be synchnrous because this directory must exist before cleanFavicons is called, and cleanFavicons returns immutableData synchronously. I could add a migration flag that indicates whether this directory was created, which would avoid having to do the synchronous mkdir in future runs.

@bsclifton
Copy link
Member

bsclifton commented Nov 20, 2017

For review status, @bridiver @NejcZdovc do you approve / not approve? @diracdeltas was any action needed on your part after the above comments?

@diracdeltas
Copy link
Member Author

@bsclifton there's some follow-up enhancements which i'll try to do early this week

@bsclifton bsclifton modified the milestones: 0.19.x Hotfix 6 (Release channel), 0.20.x (Beta Channel) Nov 28, 2017
@bsclifton
Copy link
Member

Moving to 0.20.x (as the next 0.19.x release is reserved for Chromium 63)

@diracdeltas
Copy link
Member Author

@NejcZdovc i addressed all review comments. however, i thought of something which is that the ledger-favicon/ directory should be deleted whenever the user chooses to delete payments data. do you remember if that's doable via the 'Clear browsing data...' menu item or something else in the UI?

@NejcZdovc
Copy link
Contributor

we have issue up for this option #8537, so I think that we should finally implement it 😃 will take a look and probably add it

@diracdeltas diracdeltas requested a review from NejcZdovc December 2, 2017 18:55
@diracdeltas
Copy link
Member Author

ok, if there's currently no way to clear ledger data from the session store in the UI, i don't think this PR needs to address that. ready for re-review.

This moves data:* URLs in the ledger appState to external image files, which
reduces the size of my session-store-1 from ~25 MB to 5 MB.

Fix #11582

Test plan:
1. Copy session-store-1 from a Brave profile that has had payments enabled for a while to your brave-development appData directory.
2. Start the browser and go to about:preferences#payments. The synopsis table should appear fine.
3. Close the browser.
4. In your brave-development appData directory, you should now see a ledger-favicons subdirectory which contains a lot of image files. You should also notice that session-store-1 is now much smaller.
5. Repeat step 2.
Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

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

++ this will save a lot of space

@diracdeltas diracdeltas merged commit 4e7995d into master Dec 13, 2017
@diracdeltas diracdeltas deleted the fix/remove-data-urls branch December 13, 2017 21:28
diracdeltas added a commit that referenced this pull request Dec 13, 2017
Move ledger data:* favicons to external files
diracdeltas added a commit that referenced this pull request Dec 13, 2017
Move ledger data:* favicons to external files
@diracdeltas
Copy link
Member Author

master: 4e7995d
0.21.x: ca4bc9a
0.20.x: 0b45c87

@petemill
Copy link
Member

petemill commented Feb 1, 2018

Do we have any sample large profiles with this data in, so we can assess impact and clear this change from any perf regressions we're seeing? @diracdeltas @NejcZdovc

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.

9 participants