1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-05 18:32:30 +01:00

Use prime number to generate cache-bypass token

Related discussion:
- https://github.com/gorhill/uBlock/commit/048bfd251c9b#r37972005

From <https://github.com/gwarser>:

> I think this should be "modulo prime", not 12.
> If someone always turn on PC in "8am" there is
> a slight chance to hit cache.
This commit is contained in:
Raymond Hill 2020-03-22 11:31:06 -04:00
parent 086aece6bd
commit f5204235b7
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -161,11 +161,14 @@ api.fetchText = async function(url) {
// https://github.com/uBlockOrigin/uBlock-issues/issues/682#issuecomment-515197130
// Provide filter list authors a way to completely bypass
// the browser cache.
// https://github.com/gorhill/uBlock/commit/048bfd251c9b#r37972005
// Use modulo prime numbers to avoid generating the same token at the
// same time across different days.
if ( isExternal ) {
const cacheBypassToken =
µBlock.hiddenSettings.updateAssetBypassBrowserCache
? Math.floor(Date.now() / 1000) % 86400
: Math.floor(Date.now() / 3600000) % 12;
? Math.floor(Date.now() / 1000) % 86413
: Math.floor(Date.now() / 3600000) % 13;
const queryValue = `_=${cacheBypassToken}`;
if ( actualUrl.indexOf('?') === -1 ) {
actualUrl += '?';