mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
Aggressively update assets when at least one is very obsolete
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1165
This commit is contained in:
parent
a8a46c4593
commit
f7f776fb8a
@ -1463,10 +1463,11 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µb.scheduleAssetUpdater = (( ) => {
|
||||
{
|
||||
let timer, next = 0;
|
||||
|
||||
return function(updateDelay) {
|
||||
µb.scheduleAssetUpdater = async function(updateDelay) {
|
||||
|
||||
if ( timer ) {
|
||||
clearTimeout(timer);
|
||||
timer = undefined;
|
||||
@ -1475,24 +1476,45 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
||||
next = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const assetDict = await io.metadata();
|
||||
const now = Date.now();
|
||||
|
||||
let needEmergencyUpdate = false;
|
||||
for ( const asset of Object.values(assetDict) ) {
|
||||
if ( asset.hasRemoteURL !== true ) { continue; }
|
||||
if ( asset.content === 'filters' && asset.off === true ) { continue; }
|
||||
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
|
||||
// one.
|
||||
if ( next !== 0 ) {
|
||||
updateDelay = Math.min(updateDelay, Math.max(next - now, 0));
|
||||
}
|
||||
|
||||
if ( needEmergencyUpdate ) {
|
||||
updateDelay = Math.min(updateDelay, 15000);
|
||||
}
|
||||
|
||||
next = now + updateDelay;
|
||||
|
||||
const fetchDelay = needEmergencyUpdate
|
||||
? 2000
|
||||
: this.hiddenSettings.autoUpdateAssetFetchPeriod * 1000 || 60000;
|
||||
|
||||
timer = vAPI.setTimeout(( ) => {
|
||||
timer = undefined;
|
||||
next = 0;
|
||||
io.updateStart({
|
||||
delay: this.hiddenSettings.autoUpdateAssetFetchPeriod * 1000 ||
|
||||
120000,
|
||||
auto: true,
|
||||
});
|
||||
io.updateStart({ delay: fetchDelay, auto: true });
|
||||
}, updateDelay);
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user