1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00

Discard repeating adjacent entries in the logger

This commit is contained in:
Raymond Hill 2024-01-26 09:24:10 -05:00
parent c1af7a7e0d
commit 55e4cee6e8
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
4 changed files with 12 additions and 26 deletions

View File

@ -311,7 +311,6 @@ const µBlock = { // jshint ignore:line
} }
this.fromTabId(tabId); // Must be called AFTER tab context management this.fromTabId(tabId); // Must be called AFTER tab context management
this.realm = ''; this.realm = '';
this.id = details.requestId;
this.setMethod(details.method); this.setMethod(details.method);
this.setURL(details.url); this.setURL(details.url);
this.aliasURL = details.aliasURL || undefined; this.aliasURL = details.aliasURL || undefined;
@ -373,7 +372,6 @@ const µBlock = { // jshint ignore:line
toLogger() { toLogger() {
const details = { const details = {
id: this.id,
tstamp: 0, tstamp: 0,
realm: this.realm, realm: this.realm,
method: this.getMethodName(), method: this.getMethodName(),

View File

@ -135,7 +135,6 @@ export const FilteringContext = class {
} }
this.tstamp = 0; this.tstamp = 0;
this.realm = ''; this.realm = '';
this.id = undefined;
this.method = 0; this.method = 0;
this.itype = NO_TYPE; this.itype = NO_TYPE;
this.stype = undefined; this.stype = undefined;
@ -175,7 +174,6 @@ export const FilteringContext = class {
fromFilteringContext(other) { fromFilteringContext(other) {
this.realm = other.realm; this.realm = other.realm;
this.id = other.id;
this.type = other.type; this.type = other.type;
this.method = other.method; this.method = other.method;
this.url = other.url; this.url = other.url;

View File

@ -36,6 +36,7 @@ const logger = self.logger = { ownerId: Date.now() };
const logDate = new Date(); const logDate = new Date();
const logDateTimezoneOffset = logDate.getTimezoneOffset() * 60; const logDateTimezoneOffset = logDate.getTimezoneOffset() * 60;
const loggerEntries = []; const loggerEntries = [];
let loggerEntryIdGenerator = 1;
const COLUMN_TIMESTAMP = 0; const COLUMN_TIMESTAMP = 0;
const COLUMN_FILTER = 1; const COLUMN_FILTER = 1;
@ -319,13 +320,11 @@ const LogEntry = function(details) {
if ( details instanceof Object === false ) { return; } if ( details instanceof Object === false ) { return; }
const receiver = LogEntry.prototype; const receiver = LogEntry.prototype;
for ( const prop in receiver ) { for ( const prop in receiver ) {
if ( if ( details.hasOwnProperty(prop) === false ) { continue; }
details.hasOwnProperty(prop) && if ( details[prop] === receiver[prop] ) { continue; }
details[prop] !== receiver[prop] this[prop] = details[prop];
) {
this[prop] = details[prop];
}
} }
this.id = `${loggerEntryIdGenerator++}`;
if ( details.aliasURL !== undefined ) { if ( details.aliasURL !== undefined ) {
this.aliased = true; this.aliased = true;
} }
@ -346,7 +345,6 @@ LogEntry.prototype = {
docHostname: '', docHostname: '',
domain: '', domain: '',
filter: undefined, filter: undefined,
id: '',
method: '', method: '',
realm: '', realm: '',
tabDomain: '', tabDomain: '',
@ -1627,9 +1625,10 @@ dom.on(document, 'keydown', ev => {
const aliasURLFromID = function(id) { const aliasURLFromID = function(id) {
if ( id === '' ) { return ''; } if ( id === '' ) { return ''; }
for ( const entry of loggerEntries ) { for ( const entry of loggerEntries ) {
if ( entry.id !== id || entry.aliased ) { continue; } if ( entry.id !== id ) { continue; }
const fields = entry.textContent.split('\x1F'); const match = /\baliasURL=([^\x1F]+)/.exec(entry.textContent);
return fields[COLUMN_URL] || ''; if ( match === null ) { return ''; }
return match[1];
} }
return ''; return '';
}; };

View File

@ -30,7 +30,6 @@ import { broadcast, broadcastToAll } from './broadcast.js';
let buffer = null; let buffer = null;
let lastReadTime = 0; let lastReadTime = 0;
let writePtr = 0; let writePtr = 0;
let lastBoxedEntry = '';
// After 30 seconds without being read, the logger buffer will be considered // After 30 seconds without being read, the logger buffer will be considered
// unused, and thus disabled. // unused, and thus disabled.
@ -44,7 +43,6 @@ const janitorTimer = vAPI.defer.create(( ) => {
logger.enabled = false; logger.enabled = false;
buffer = null; buffer = null;
writePtr = 0; writePtr = 0;
lastBoxedEntry = '';
logger.ownerId = undefined; logger.ownerId = undefined;
broadcastToAll({ what: 'loggerDisabled' }); broadcastToAll({ what: 'loggerDisabled' });
}); });
@ -55,6 +53,7 @@ const boxEntry = details => {
}; };
const pushOne = box => { const pushOne = box => {
if ( writePtr !== 0 && box === buffer[writePtr-1] ) { return; }
if ( writePtr === buffer.length ) { if ( writePtr === buffer.length ) {
buffer.push(box); buffer.push(box);
} else { } else {
@ -68,12 +67,7 @@ const logger = {
ownerId: undefined, ownerId: undefined,
writeOne(details) { writeOne(details) {
if ( buffer === null ) { return; } if ( buffer === null ) { return; }
const box = boxEntry(details); pushOne(boxEntry(details));
if ( box === lastBoxedEntry ) { return; }
if ( lastBoxedEntry !== '' ) {
pushOne(lastBoxedEntry);
}
lastBoxedEntry = box;
}, },
readAll(ownerId) { readAll(ownerId) {
this.ownerId = ownerId; this.ownerId = ownerId;
@ -83,11 +77,8 @@ const logger = {
janitorTimer.on(logBufferObsoleteAfter); janitorTimer.on(logBufferObsoleteAfter);
broadcast({ what: 'loggerEnabled' }); broadcast({ what: 'loggerEnabled' });
} }
if ( lastBoxedEntry !== '' ) {
pushOne(lastBoxedEntry);
lastBoxedEntry = '';
}
const out = buffer.slice(0, writePtr); const out = buffer.slice(0, writePtr);
buffer.fill('', 0, writePtr);
writePtr = 0; writePtr = 0;
lastReadTime = Date.now(); lastReadTime = Date.now();
return out; return out;