mirror of https://github.com/gorhill/uBlock.git
Lookup asset key from diff name
Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/2948 This fix has to make it into next stable release to ensure imported external lists can benefit from diff-updater.
This commit is contained in:
parent
5b7d951c4b
commit
9f52b4763e
|
@ -172,6 +172,27 @@ const isDiffUpdatableAsset = content => {
|
||||||
data.diffPath.startsWith('%') === false;
|
data.diffPath.startsWith('%') === false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const assetKeyFromDiffName = diffName => {
|
||||||
|
const entry = assetCacheRegistry[diffName];
|
||||||
|
if ( entry instanceof Object ) {
|
||||||
|
if ( typeof entry.diffPath === 'string' ) {
|
||||||
|
if ( entry.diffPath.endsWith(`#${diffName}`) ) { return diffName; }
|
||||||
|
}
|
||||||
|
if ( typeof entry.diffName === 'string' ) {
|
||||||
|
if ( entry.diffName === diffName ) { return diffName; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for ( const [ assetKey, entry ] of Object.entries(assetCacheRegistry) ) {
|
||||||
|
if ( typeof entry.diffPath === 'string' ) {
|
||||||
|
if ( entry.diffPath.endsWith(`#${diffName}`) ) { return assetKey; }
|
||||||
|
}
|
||||||
|
if ( typeof entry.diffName === 'string' ) {
|
||||||
|
if ( entry.diffName === diffName ) { return assetKey; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// favorLocal: avoid making network requests whenever possible
|
// favorLocal: avoid making network requests whenever possible
|
||||||
|
@ -1237,7 +1258,8 @@ async function diffUpdater() {
|
||||||
}
|
}
|
||||||
if ( data.status === 'needtext' ) {
|
if ( data.status === 'needtext' ) {
|
||||||
ubolog('Diff updater: need text for', data.name);
|
ubolog('Diff updater: need text for', data.name);
|
||||||
assetCacheRead(data.name).then(result => {
|
const assetKey = assetKeyFromDiffName(data.name);
|
||||||
|
assetCacheRead(assetKey).then(result => {
|
||||||
data.text = result.content;
|
data.text = result.content;
|
||||||
data.status = undefined;
|
data.status = undefined;
|
||||||
bc.postMessage(data);
|
bc.postMessage(data);
|
||||||
|
@ -1253,22 +1275,24 @@ async function diffUpdater() {
|
||||||
'Diff-Path',
|
'Diff-Path',
|
||||||
'Diff-Expires',
|
'Diff-Expires',
|
||||||
]);
|
]);
|
||||||
assetCacheWrite(data.name, {
|
const assetKey = assetKeyFromDiffName(data.name);
|
||||||
|
assetCacheWrite(assetKey, {
|
||||||
content: data.text,
|
content: data.text,
|
||||||
resourceTime: metadata.lastModified || 0,
|
resourceTime: metadata.lastModified || 0,
|
||||||
});
|
});
|
||||||
assetCacheSetDetails(data.name, metadata);
|
assetCacheSetDetails(assetKey, metadata);
|
||||||
updaterUpdated.push(data.name);
|
updaterUpdated.push(assetKey);
|
||||||
} else if ( data.error ) {
|
} else if ( data.error ) {
|
||||||
ubolog(`Diff updater: failed to update ${data.name} using ${data.patchPath}, reason: ${data.error}`);
|
ubolog(`Diff updater: failed to update ${data.name} using ${data.patchPath}, reason: ${data.error}`);
|
||||||
} else if ( data.status === 'nopatch-yet' || data.status === 'nodiff' ) {
|
} else if ( data.status === 'nopatch-yet' || data.status === 'nodiff' ) {
|
||||||
ubolog(`Diff updater: skip update of ${data.name} using ${data.patchPath}, reason: ${data.status}`);
|
ubolog(`Diff updater: skip update of ${data.name} using ${data.patchPath}, reason: ${data.status}`);
|
||||||
assetCacheSetDetails(data.name, {
|
const assetKey = assetKeyFromDiffName(data.name);
|
||||||
|
assetCacheSetDetails(assetKey, {
|
||||||
writeTime: data.lastModified || 0
|
writeTime: data.lastModified || 0
|
||||||
});
|
});
|
||||||
vAPI.messaging.broadcast({
|
vAPI.messaging.broadcast({
|
||||||
what: 'assetUpdated',
|
what: 'assetUpdated',
|
||||||
key: data.name,
|
key: assetKey,
|
||||||
cached: true,
|
cached: true,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue