Don't store domains on disk that don't track#1462
Conversation
|
TODO:
|
| return false; | ||
| } | ||
|
|
||
| function ifRelevant(details, callback) { |
There was a problem hiding this comment.
I need to document these functions.
| * Wraps _recordPrevalence for use from webRequest listeners. | ||
| * Also saves tab (page) origins. TODO Should be handled by tabData instead. | ||
| * Also sets a timeout for checking DNT policy for third-party FQDNs. | ||
| * TODO Does too much, should be broken up ... |
There was a problem hiding this comment.
update this docstring
There was a problem hiding this comment.
|
|
||
| function onRelevantBeforeSendHeaders(details, fqdn, origin, tabOrigin) { | ||
| badger.checkForDNTPolicy(fqdn, badger.storage.getNextUpdateForDomain(fqdn)); | ||
| return heuristicBlockingAccounting(details, fqdn, origin, tabOrigin); |
There was a problem hiding this comment.
I broke this out into a separate function because I was speculating about performance. I should measure this before it gets committed.
|
On master, after visiting 100 sites, the |
|
Ready for review |
|
Closes #1446 |
|
Does anyone have a set of exported storage data I could use to test this migration? cc @alexristich @terrorist96 EDIT: Or if you'd like to keep the data to yourself, you are welcome to test out these changes yourself. |
|
Sure, let me know where I can email you the file. |
|
Sure, but as I noted in #1318, I can't export my data. |
|
@alexristich I emailed you. @terrorist96 If you want to try running this branch, it should dramatically reduce the size of your storage. However this is a testing branch, so I can't guarantee that it won't mess up your PB installation. |
|
I'll wait for the next stable version. 😃 |
| badger.storage.touchDNTRecheckTime(domain, recheckTime); | ||
|
|
||
| this._checkPrivacyBadgerPolicy(domain, function (success) { | ||
| self._checkPrivacyBadgerPolicy(domain, function (success) { |
There was a problem hiding this comment.
Looking at it, maybe it's a good time to rename _checkPrivacyBadgerPolicy to _checkDNTPolicy to make it more consistent.
| return _processWebRequest(details, heuristicBlockingAccounting, true); | ||
| } | ||
|
|
||
| function onBeforeResponseStarted(details) { |
There was a problem hiding this comment.
onBeforeResponseStarted -> onResponseStarted so as to match the webRequest API. Might be removed in a future PR, though in case it doesn't we should fix it here.
| this._setupDomainAction(domain, action, "heuristicAction"); | ||
| if (this.isActionMapEmptyForDomain(domain)) { | ||
| this.getBadgerStorageObject('action_map').deleteItem(domain); | ||
| } |
There was a problem hiding this comment.
Is this if condition ever true? A quick check in the code doesn't reveal any cases where setupHeuristicAction is called with either "" or constants.NO_TRACKING.
There was a problem hiding this comment.
You are correct we do not do that anywhere. It is totally preventative.
I want this layer of the API (things wrapping _setupDomainAction) to manage garbage collecting action_map objects. Without this, there is a leak in that abstraction.
There was a problem hiding this comment.
Ah, good thinking. Best not have to end up with another migration to fix the same issue in the future :)
| CheckedDNTBuffer.prototype = { | ||
| size: 1000, | ||
| // if we've seen item, return true. if we haven't store it and return false | ||
| hasOrSet: function(item) { |
There was a problem hiding this comment.
I find the name hasOrSet to be a tad confusing.
Could it instead be split into two functions? One being has(), which checks if a domain has already been checked. Another which is add(), which is called in the case that _checkPrivacyBadgerPolicy() returns false to the callback.
I believe this would also eliminate the need for an explicit delete() function, as we wouldn't be adding anything that might need to be removed.
There was a problem hiding this comment.
I agree hasOrSet is a bad name, I'm open to suggestions.
But I don't think breaking it into two functions is the correct thing to do, I actually considered mimicking the Set api first (like you suggest). However if add gets put into the callback, then the domain won't get added until the dnt check finishes, which could take a while, possibly after we ask for another DNT check for the same domain.
I also think having a seperate add and has could lead to misuse of the API. For example add might be called on an item that is already in the buffer. I could guard against this inside add to make it it idempotent, but then I'd be checking the set for containment of the domain twice for my main use case which is what happenes in the hasOrSet function.
There was a problem hiding this comment.
I'm not sure misuse of the API ought to be a huge concern; making it idempotent is fairly light (considering it's a couple lines of code and a constant time operation). I guess my only thought then is whether an adequate name can be found that makes it clear what this is expected to do.
How about something like containsOrInsert or containsOrAdd?
There was a problem hiding this comment.
How about isContaintedAndAddIfNot?
I do think API misuse is a pretty big concern. I don't trust myself to come back to this code in 2 years and remember that I'm only supposed to call add after has.
There was a problem hiding this comment.
Haha, fair enough. Maybe hasElseAdd to keep it a bit more concise?
|
Huge improvements, looking nice! I left a few short comments; hopefully some of it is of use. @ghostwords give this PR a look when you get a chance. |
|
@ghostwords Here are the changes to
The problem here is that DNT checking didn't need to happen for the So I moved the proccessing and DNT check into a I also avoided putting anonymous functions in the webrequest listeners, https://developers.google.com/speed/articles/optimizing-javascript#avoiding-pitfalls-with-closures |
5698509 to
c1241ad
Compare
|
@ghostwords I fixed that test. It was failing from the changes I made to how DNT is rechecked. Instead of getting ratelimited we were discarding extra calls since they had already been checked. So now I test that the internal This is ready for review. |
|
Just a quick note, the "closes"/"fixes" references to the original issue only work in the description of the ticket, not the subject or the comments. I updated the description to include the reference. |
b18cdb6 to
e4edcfa
Compare
|
Could you please rebase and resolve conflicts? |
This codepath was only being used by the special "third-strike" code path which was removed. So it is unneeded.
e4edcfa to
e689a57
Compare
|
Blocked by #1642 |
|
Closing in favor of #1795. |
With this PR we no longer store "empty" action map objects on disk, meaning the action map has no user action, no dnt, and no tracking (but the action map would have a domain and timestamp).
A lot of our DNT checking depended on these "empty" action map objects. Before, we would use the timestamp to know when to recheck.
Now we keep up to the last 1000 "empty" domains we've seen in memory. We don't recheck a domain if we have it in this data structure.
The first commit 91364da makes it so we don't create an action map object for a domain when get a negative check for DNT
Then e410490 cleans up actionMap objects that become "empty". Like when a domain has some user action, but nothing else, but then the user action gets reverted.
Then from 9cd4bae to 01ff998 I change the way we recheck for DNT.
Closes #1446.