mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-02 00:42:45 +01:00
Prevent repeatedly launching emergency updates
Emergency update of assets could be repeatedly launched every 15 seconds if a resource could not be fetched from a server. A cooldown period has been added to prevent repeatedly launching emergency updates.
This commit is contained in:
parent
8d445e782d
commit
6461393b6a
@ -1465,6 +1465,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
|
|
||||||
{
|
{
|
||||||
let timer, next = 0;
|
let timer, next = 0;
|
||||||
|
let lastEmergencyUpdate = 0;
|
||||||
|
|
||||||
µb.scheduleAssetUpdater = async function(updateDelay) {
|
µb.scheduleAssetUpdater = async function(updateDelay) {
|
||||||
|
|
||||||
@ -1477,23 +1478,28 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const assetDict = await io.metadata();
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
let needEmergencyUpdate = false;
|
let needEmergencyUpdate = false;
|
||||||
for ( const [ assetKey, asset ] of Object.entries(assetDict) ) {
|
|
||||||
if ( asset.hasRemoteURL !== true ) { continue; }
|
// Respect cooldown period before launching an emergency update.
|
||||||
if ( asset.content === 'filters' ) {
|
const timeSinceLastEmergencyUpdate = (now - lastEmergencyUpdate) / 3600000;
|
||||||
if ( µb.selectedFilterLists.includes(assetKey) === false ) {
|
if ( timeSinceLastEmergencyUpdate > 1 ) {
|
||||||
continue;
|
const assetDict = await io.metadata();
|
||||||
|
for ( const [ assetKey, asset ] of Object.entries(assetDict) ) {
|
||||||
|
if ( asset.hasRemoteURL !== true ) { continue; }
|
||||||
|
if ( asset.content === 'filters' ) {
|
||||||
|
if ( µb.selectedFilterLists.includes(assetKey) === false ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if ( asset.obsolete !== true ) { continue; }
|
||||||
|
const lastUpdateInDays = (now - asset.writeTime) / 86400000;
|
||||||
|
const daysSinceVeryObsolete = lastUpdateInDays - 2 * asset.updateAfter;
|
||||||
|
if ( daysSinceVeryObsolete < 0 ) { continue; }
|
||||||
|
needEmergencyUpdate = true;
|
||||||
|
lastEmergencyUpdate = now;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if ( asset.obsolete !== true ) { continue; }
|
|
||||||
const lastUpdateInDays = (now - asset.writeTime) / 86400000;
|
|
||||||
const daysSinceVeryObsolete = lastUpdateInDays - 2 * asset.updateAfter;
|
|
||||||
if ( daysSinceVeryObsolete < 0 ) { continue; }
|
|
||||||
needEmergencyUpdate = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the new schedule if and only if it is earlier than the previous
|
// Use the new schedule if and only if it is earlier than the previous
|
||||||
|
Loading…
Reference in New Issue
Block a user