mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-18 08:52:26 +02:00
code review: avoid compiling twice when list is fetched from remote location the 1st time
This commit is contained in:
parent
1de523b7bf
commit
3109d19e3c
@ -658,21 +658,34 @@
|
|||||||
|
|
||||||
µBlock.getCompiledFilterList = function(assetKey, callback) {
|
µBlock.getCompiledFilterList = function(assetKey, callback) {
|
||||||
var µb = this,
|
var µb = this,
|
||||||
compiledPath = 'compiled/' + assetKey;
|
compiledPath = 'compiled/' + assetKey,
|
||||||
|
rawContent;
|
||||||
|
|
||||||
|
var onCompiledListLoaded2 = function(details) {
|
||||||
|
if ( details.content === '' ) {
|
||||||
|
details.content = µb.compileFilters(rawContent);
|
||||||
|
µb.assets.put(compiledPath, details.content);
|
||||||
|
}
|
||||||
|
rawContent = undefined;
|
||||||
|
details.assetKey = assetKey;
|
||||||
|
callback(details);
|
||||||
|
};
|
||||||
|
|
||||||
var onRawListLoaded = function(details) {
|
var onRawListLoaded = function(details) {
|
||||||
details.assetKey = assetKey;
|
|
||||||
if ( details.content === '' ) {
|
if ( details.content === '' ) {
|
||||||
|
details.assetKey = assetKey;
|
||||||
callback(details);
|
callback(details);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
µb.extractFilterListMetadata(assetKey, details.content);
|
µb.extractFilterListMetadata(assetKey, details.content);
|
||||||
details.content = µb.compileFilters(details.content);
|
// Fectching the raw content may cause the compiled content to be
|
||||||
µb.assets.put(compiledPath, details.content);
|
// generated somewhere else in uBO, hence we try one last time to
|
||||||
callback(details);
|
// fetch the compiled content in case it has become available.
|
||||||
|
rawContent = details.content;
|
||||||
|
µb.assets.get(compiledPath, onCompiledListLoaded2);
|
||||||
};
|
};
|
||||||
|
|
||||||
var onCompiledListLoaded = function(details) {
|
var onCompiledListLoaded1 = function(details) {
|
||||||
if ( details.content === '' ) {
|
if ( details.content === '' ) {
|
||||||
µb.assets.get(assetKey, onRawListLoaded);
|
µb.assets.get(assetKey, onRawListLoaded);
|
||||||
return;
|
return;
|
||||||
@ -681,7 +694,7 @@
|
|||||||
callback(details);
|
callback(details);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.assets.get(compiledPath, onCompiledListLoaded);
|
this.assets.get(compiledPath, onCompiledListLoaded1);
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user