Skip to content

Commit

Permalink
Discard repeating adjacent entries in the logger
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jan 26, 2024
1 parent c1af7a7 commit 55e4cee
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
2 changes: 0 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ const µBlock = { // jshint ignore:line
}
this.fromTabId(tabId); // Must be called AFTER tab context management
this.realm = '';
this.id = details.requestId;
this.setMethod(details.method);
this.setURL(details.url);
this.aliasURL = details.aliasURL || undefined;
Expand Down Expand Up @@ -373,7 +372,6 @@ const µBlock = { // jshint ignore:line

toLogger() {
const details = {
id: this.id,
tstamp: 0,
realm: this.realm,
method: this.getMethodName(),
Expand Down
2 changes: 0 additions & 2 deletions src/js/filtering-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export const FilteringContext = class {
}
this.tstamp = 0;
this.realm = '';
this.id = undefined;
this.method = 0;
this.itype = NO_TYPE;
this.stype = undefined;
Expand Down Expand Up @@ -175,7 +174,6 @@ export const FilteringContext = class {

fromFilteringContext(other) {
this.realm = other.realm;
this.id = other.id;
this.type = other.type;
this.method = other.method;
this.url = other.url;
Expand Down
19 changes: 9 additions & 10 deletions src/js/logger-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const logger = self.logger = { ownerId: Date.now() };
const logDate = new Date();
const logDateTimezoneOffset = logDate.getTimezoneOffset() * 60;
const loggerEntries = [];
let loggerEntryIdGenerator = 1;

const COLUMN_TIMESTAMP = 0;
const COLUMN_FILTER = 1;
Expand Down Expand Up @@ -319,13 +320,11 @@ const LogEntry = function(details) {
if ( details instanceof Object === false ) { return; }
const receiver = LogEntry.prototype;
for ( const prop in receiver ) {
if (
details.hasOwnProperty(prop) &&
details[prop] !== receiver[prop]
) {
this[prop] = details[prop];
}
if ( details.hasOwnProperty(prop) === false ) { continue; }
if ( details[prop] === receiver[prop] ) { continue; }
this[prop] = details[prop];
}
this.id = `${loggerEntryIdGenerator++}`;
if ( details.aliasURL !== undefined ) {
this.aliased = true;
}
Expand All @@ -346,7 +345,6 @@ LogEntry.prototype = {
docHostname: '',
domain: '',
filter: undefined,
id: '',
method: '',
realm: '',
tabDomain: '',
Expand Down Expand Up @@ -1627,9 +1625,10 @@ dom.on(document, 'keydown', ev => {
const aliasURLFromID = function(id) {
if ( id === '' ) { return ''; }
for ( const entry of loggerEntries ) {
if ( entry.id !== id || entry.aliased ) { continue; }
const fields = entry.textContent.split('\x1F');
return fields[COLUMN_URL] || '';
if ( entry.id !== id ) { continue; }
const match = /\baliasURL=([^\x1F]+)/.exec(entry.textContent);
if ( match === null ) { return ''; }
return match[1];
}
return '';
};
Expand Down
15 changes: 3 additions & 12 deletions src/js/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { broadcast, broadcastToAll } from './broadcast.js';
let buffer = null;
let lastReadTime = 0;
let writePtr = 0;
let lastBoxedEntry = '';

// After 30 seconds without being read, the logger buffer will be considered
// unused, and thus disabled.
Expand All @@ -44,7 +43,6 @@ const janitorTimer = vAPI.defer.create(( ) => {
logger.enabled = false;
buffer = null;
writePtr = 0;
lastBoxedEntry = '';
logger.ownerId = undefined;
broadcastToAll({ what: 'loggerDisabled' });
});
Expand All @@ -55,6 +53,7 @@ const boxEntry = details => {
};

const pushOne = box => {
if ( writePtr !== 0 && box === buffer[writePtr-1] ) { return; }
if ( writePtr === buffer.length ) {
buffer.push(box);
} else {
Expand All @@ -68,12 +67,7 @@ const logger = {
ownerId: undefined,
writeOne(details) {
if ( buffer === null ) { return; }
const box = boxEntry(details);
if ( box === lastBoxedEntry ) { return; }
if ( lastBoxedEntry !== '' ) {
pushOne(lastBoxedEntry);
}
lastBoxedEntry = box;
pushOne(boxEntry(details));
},
readAll(ownerId) {
this.ownerId = ownerId;
Expand All @@ -83,11 +77,8 @@ const logger = {
janitorTimer.on(logBufferObsoleteAfter);
broadcast({ what: 'loggerEnabled' });
}
if ( lastBoxedEntry !== '' ) {
pushOne(lastBoxedEntry);
lastBoxedEntry = '';
}
const out = buffer.slice(0, writePtr);
buffer.fill('', 0, writePtr);
writePtr = 0;
lastReadTime = Date.now();
return out;
Expand Down

0 comments on commit 55e4cee

Please sign in to comment.