Fix visit tracking and add locking for storing data #104
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #101
Visit tracking was broken for sites that have delayed monetization events, such as adapted sites like YouTube and sites that enable monetization via iframes.
Now, we register a visit in
originStats
for every page visited and only increment theoriginData
monetized visits once we know that the site is monetized.In collaboration with @vezwork, locking has been added for storing data. During my testing, I noticed that data was getting overwritten, since many asynchronous requests to store to browser storage can occur at the same time. To ensure that data stores do not run over each other, locking around the data storing is needed so that writing to local browser storage occurs sequentially.
Even with this locking addition, we think there might be some errors with storing between tab switches. This is because saving data to browser storage is happening on a per-origin basis, but the data being stored is to the same place in browser storage, so there may be issues with losing/overwriting data. Opened #103 to start discussion about this.