Provide compiler/selfie versions for snfe

So as to allow nodejs usage to better deal with
out of date serialization/compilation.

Additionally, use FilterImportant() only when a
"block-important" filter is stored in the "block" realm.
This commit is contained in:
Raymond Hill 2021-08-16 12:15:30 -04:00
parent 30e46ba64a
commit a33f70cf20
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 18 additions and 15 deletions

View File

@ -3431,11 +3431,6 @@ class FilterCompiler {
units.push(FilterAnchorRight.compile()); units.push(FilterAnchorRight.compile());
} }
// Important
if ( (this.action & Important) !== 0 ) {
units.push(FilterImportant.compile());
}
// Strict partiness // Strict partiness
if ( this.strictParty !== 0 ) { if ( this.strictParty !== 0 ) {
units.push(FilterStrictParty.compile(this)); units.push(FilterStrictParty.compile(this));
@ -3469,11 +3464,12 @@ class FilterCompiler {
this.action = (this.action & ~ActionBitsMask) | ModifyAction; this.action = (this.action & ~ActionBitsMask) | ModifyAction;
} }
const fdata = units.length === 1 this.compileToAtomicFilter(
units.length === 1
? units[0] ? units[0]
: FilterCompositeAll.compile(units); : FilterCompositeAll.compile(units),
writer
this.compileToAtomicFilter(fdata, writer); );
// Add block-important filters to the block realm, so as to avoid // Add block-important filters to the block realm, so as to avoid
// to unconditionally match against the block-important realm for // to unconditionally match against the block-important realm for
@ -3483,7 +3479,11 @@ class FilterCompiler {
// meant to override. // meant to override.
if ( (this.action & BlockImportant) !== 0 ) { if ( (this.action & BlockImportant) !== 0 ) {
this.action &= ~Important; this.action &= ~Important;
this.compileToAtomicFilter(fdata, writer); units.push(FilterImportant.compile());
this.compileToAtomicFilter(
FilterCompositeAll.compile(units),
writer
);
} }
} }
@ -3537,6 +3537,9 @@ FilterCompiler.prototype.FILTER_UNSUPPORTED = 2;
/******************************************************************************/ /******************************************************************************/
const FilterContainer = function() { const FilterContainer = function() {
this.compilerVersion = '1';
this.selfieVersion = '1';
this.MAX_TOKEN_LENGTH = MAX_TOKEN_LENGTH; this.MAX_TOKEN_LENGTH = MAX_TOKEN_LENGTH;
this.optimizeTimerId = undefined; this.optimizeTimerId = undefined;
// As long as CategoryCount is reasonably low, we will use an array to // As long as CategoryCount is reasonably low, we will use an array to
@ -3768,6 +3771,7 @@ FilterContainer.prototype.toSelfie = function(storage, path) {
storage.put( storage.put(
`${path}/main`, `${path}/main`,
JSON.stringify({ JSON.stringify({
version: this.selfieVersion,
processedFilterCount: this.processedFilterCount, processedFilterCount: this.processedFilterCount,
acceptedCount: this.acceptedCount, acceptedCount: this.acceptedCount,
rejectedCount: this.rejectedCount, rejectedCount: this.rejectedCount,
@ -3831,6 +3835,7 @@ FilterContainer.prototype.fromSelfie = function(storage, path) {
} catch (ex) { } catch (ex) {
} }
if ( selfie instanceof Object === false ) { return false; } if ( selfie instanceof Object === false ) { return false; }
if ( selfie.version !== this.selfieVersion ) { return false; }
this.processedFilterCount = selfie.processedFilterCount; this.processedFilterCount = selfie.processedFilterCount;
this.acceptedCount = selfie.acceptedCount; this.acceptedCount = selfie.acceptedCount;
this.rejectedCount = selfie.rejectedCount; this.rejectedCount = selfie.rejectedCount;

View File

@ -866,10 +866,8 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
this.badLists.has(assetKey) === false this.badLists.has(assetKey) === false
) { ) {
const compiledDetails = await io.get(compiledPath); const compiledDetails = await io.get(compiledPath);
if ( const compilerVersion = `${this.systemSettings.compiledMagic}\n`;
parseInt(compiledDetails.content, 10) === if ( compiledDetails.content.startsWith(compilerVersion) ) {
this.systemSettings.compiledMagic
) {
compiledDetails.assetKey = assetKey; compiledDetails.assetKey = assetKey;
return compiledDetails; return compiledDetails;
} }