1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 07:22:28 +02:00

Auto-update most obsolete asset first

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1165
This commit is contained in:
Raymond Hill 2020-07-21 07:50:36 -04:00
parent 4832552950
commit 3839d05a99
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -884,7 +884,7 @@ const updateNext = async function() {
]); ]);
const now = Date.now(); const now = Date.now();
let assetKeyToUpdate; const toUpdate = [];
for ( const assetKey in assetDict ) { for ( const assetKey in assetDict ) {
const assetEntry = assetDict[assetKey]; const assetEntry = assetDict[assetKey];
if ( assetEntry.hasRemoteURL !== true ) { continue; } if ( assetEntry.hasRemoteURL !== true ) { continue; }
@ -902,23 +902,30 @@ const updateNext = async function() {
type: assetEntry.content type: assetEntry.content
}) === true }) === true
) { ) {
assetKeyToUpdate = assetKey; toUpdate.push(assetKey);
break; continue;
} }
// This will remove a cached asset when it's no longer in use. // This will remove a cached asset when it's no longer in use.
if ( cacheEntry && cacheEntry.readTime < assetCacheRegistryStartTime ) { if ( cacheEntry && cacheEntry.readTime < assetCacheRegistryStartTime ) {
assetCacheRemove(assetKey); assetCacheRemove(assetKey);
} }
} }
if ( assetKeyToUpdate === undefined ) { if ( toUpdate.length === 0 ) {
return updateDone(); return updateDone();
} }
updaterFetched.add(assetKeyToUpdate); // https://github.com/uBlockOrigin/uBlock-issues/issues/1165
// Update most obsolete asset first.
toUpdate.sort((a, b) => {
const ta = cacheDict[a] !== undefined ? cacheDict[a].writeTime : 0;
const tb = cacheDict[b] !== undefined ? cacheDict[b].writeTime : 0;
return ta - tb;
});
updaterFetched.add(toUpdate[0]);
// In auto-update context, be gentle on remote servers. // In auto-update context, be gentle on remote servers.
remoteServerFriendly = updaterAuto; remoteServerFriendly = updaterAuto;
const result = await getRemote(assetKeyToUpdate); const result = await getRemote(toUpdate[0]);
remoteServerFriendly = false; remoteServerFriendly = false;