Skip to content

Commit 55e4cee

Browse files
committed
Discard repeating adjacent entries in the logger
1 parent c1af7a7 commit 55e4cee

4 files changed

Lines changed: 12 additions & 26 deletions

File tree

src/js/background.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ const µBlock = { // jshint ignore:line
311311
}
312312
this.fromTabId(tabId); // Must be called AFTER tab context management
313313
this.realm = '';
314-
this.id = details.requestId;
315314
this.setMethod(details.method);
316315
this.setURL(details.url);
317316
this.aliasURL = details.aliasURL || undefined;
@@ -373,7 +372,6 @@ const µBlock = { // jshint ignore:line
373372

374373
toLogger() {
375374
const details = {
376-
id: this.id,
377375
tstamp: 0,
378376
realm: this.realm,
379377
method: this.getMethodName(),

src/js/filtering-context.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ export const FilteringContext = class {
135135
}
136136
this.tstamp = 0;
137137
this.realm = '';
138-
this.id = undefined;
139138
this.method = 0;
140139
this.itype = NO_TYPE;
141140
this.stype = undefined;
@@ -175,7 +174,6 @@ export const FilteringContext = class {
175174

176175
fromFilteringContext(other) {
177176
this.realm = other.realm;
178-
this.id = other.id;
179177
this.type = other.type;
180178
this.method = other.method;
181179
this.url = other.url;

src/js/logger-ui.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const logger = self.logger = { ownerId: Date.now() };
3636
const logDate = new Date();
3737
const logDateTimezoneOffset = logDate.getTimezoneOffset() * 60;
3838
const loggerEntries = [];
39+
let loggerEntryIdGenerator = 1;
3940

4041
const COLUMN_TIMESTAMP = 0;
4142
const COLUMN_FILTER = 1;
@@ -319,13 +320,11 @@ const LogEntry = function(details) {
319320
if ( details instanceof Object === false ) { return; }
320321
const receiver = LogEntry.prototype;
321322
for ( const prop in receiver ) {
322-
if (
323-
details.hasOwnProperty(prop) &&
324-
details[prop] !== receiver[prop]
325-
) {
326-
this[prop] = details[prop];
327-
}
323+
if ( details.hasOwnProperty(prop) === false ) { continue; }
324+
if ( details[prop] === receiver[prop] ) { continue; }
325+
this[prop] = details[prop];
328326
}
327+
this.id = `${loggerEntryIdGenerator++}`;
329328
if ( details.aliasURL !== undefined ) {
330329
this.aliased = true;
331330
}
@@ -346,7 +345,6 @@ LogEntry.prototype = {
346345
docHostname: '',
347346
domain: '',
348347
filter: undefined,
349-
id: '',
350348
method: '',
351349
realm: '',
352350
tabDomain: '',
@@ -1627,9 +1625,10 @@ dom.on(document, 'keydown', ev => {
16271625
const aliasURLFromID = function(id) {
16281626
if ( id === '' ) { return ''; }
16291627
for ( const entry of loggerEntries ) {
1630-
if ( entry.id !== id || entry.aliased ) { continue; }
1631-
const fields = entry.textContent.split('\x1F');
1632-
return fields[COLUMN_URL] || '';
1628+
if ( entry.id !== id ) { continue; }
1629+
const match = /\baliasURL=([^\x1F]+)/.exec(entry.textContent);
1630+
if ( match === null ) { return ''; }
1631+
return match[1];
16331632
}
16341633
return '';
16351634
};

src/js/logger.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { broadcast, broadcastToAll } from './broadcast.js';
3030
let buffer = null;
3131
let lastReadTime = 0;
3232
let writePtr = 0;
33-
let lastBoxedEntry = '';
3433

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

5755
const pushOne = box => {
56+
if ( writePtr !== 0 && box === buffer[writePtr-1] ) { return; }
5857
if ( writePtr === buffer.length ) {
5958
buffer.push(box);
6059
} else {
@@ -68,12 +67,7 @@ const logger = {
6867
ownerId: undefined,
6968
writeOne(details) {
7069
if ( buffer === null ) { return; }
71-
const box = boxEntry(details);
72-
if ( box === lastBoxedEntry ) { return; }
73-
if ( lastBoxedEntry !== '' ) {
74-
pushOne(lastBoxedEntry);
75-
}
76-
lastBoxedEntry = box;
70+
pushOne(boxEntry(details));
7771
},
7872
readAll(ownerId) {
7973
this.ownerId = ownerId;
@@ -83,11 +77,8 @@ const logger = {
8377
janitorTimer.on(logBufferObsoleteAfter);
8478
broadcast({ what: 'loggerEnabled' });
8579
}
86-
if ( lastBoxedEntry !== '' ) {
87-
pushOne(lastBoxedEntry);
88-
lastBoxedEntry = '';
89-
}
9080
const out = buffer.slice(0, writePtr);
81+
buffer.fill('', 0, writePtr);
9182
writePtr = 0;
9283
lastReadTime = Date.now();
9384
return out;

0 commit comments

Comments
 (0)