@whotracksme/reporting 12.1.14 β†’ 12.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v12.1.15 (Thu Nov 19 2026)
2
+
3
+ #### πŸ› Bug Fix
4
+
5
+ - Fixed bloom filter cleanup [#257](https://github.com/whotracksme/webextension-packages/pull/257) ([@philipp-classen](https://github.com/philipp-classen))
6
+
7
+ #### Authors: 1
8
+
9
+ - Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
10
+
11
+ ---
12
+
1
13
  # v12.1.14 (Thu Nov 19 2026)
2
14
 
3
15
  #### πŸ› Bug Fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whotracksme/reporting",
3
- "version": "12.1.14",
3
+ "version": "12.1.15",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./sanitizer": "./reporting/src/sanitizer.js",
@@ -192,7 +192,7 @@ export class BloomFilter {
192
192
  try {
193
193
  await Promise.all(
194
194
  [...corruptedKeys, ...obsoleteKeys].map((key) =>
195
- this.db.delete(key),
195
+ this.db.remove(key),
196
196
  ),
197
197
  );
198
198
  this._info('Successfully cleaned up keys');
@@ -238,7 +238,7 @@ export class BloomFilter {
238
238
  if (this.maxGenerations > 1) {
239
239
  const isTooOld = (ts) =>
240
240
  ts < now - this.rotationIntervalInMs * this.maxGenerations;
241
- while (currentGens.size > 0 && isTooOld(currentGens[0])) {
241
+ while (currentGens.length > 0 && isTooOld(currentGens[0])) {
242
242
  const oldestGen = currentGens.shift();
243
243
  gensToDelete.push(oldestGen);
244
244
  this._info('detected old generation:', oldestGen);
@@ -269,7 +269,7 @@ export class BloomFilter {
269
269
  this._info('Deleting generation', gen);
270
270
  const keys = keysByGen.get(gen);
271
271
  try {
272
- await Promise.all(keys.map((key) => this.db.delete(key)));
272
+ await Promise.all(keys.map((key) => this.db.remove(key)));
273
273
  this._info(
274
274
  `Generation ${gen} successfully deleted (${keys.length} keys in total)`,
275
275
  );
@@ -278,7 +278,7 @@ export class BloomFilter {
278
278
  }
279
279
  });
280
280
  }
281
- await Promise.all(pendingCleanups);
281
+ await Promise.all(pendingCleanups.map((cleanup) => cleanup()));
282
282
 
283
283
  this.generations = currentGens.map(
284
284
  (gen) =>
@@ -78,11 +78,11 @@ export default class PersistedBitarray {
78
78
  const unmatchedKeys = [...remainingKeys];
79
79
  this._warn(
80
80
  'Found',
81
- unmatchedKeys.size,
81
+ unmatchedKeys.length,
82
82
  'unmatched keys (will be deleted):',
83
83
  unmatchedKeys,
84
84
  );
85
- Promise.all(unmatchedKeys.map((key) => this.db.deleteKey(key)))
85
+ Promise.all(unmatchedKeys.map((key) => this.db.remove(key)))
86
86
  .then(() => this._info('Unmatched keys successfully removed'))
87
87
  .catch((e) => this._warn('Failed to delete keys', e));
88
88
  }
@@ -28,9 +28,13 @@ describe('#BloomFilter', function () {
28
28
  });
29
29
  }
30
30
 
31
+ async function flushToDisk(bloomFilter) {
32
+ await Promise.all(bloomFilter.generations.map((gen) => gen.flush()));
33
+ }
34
+
31
35
  // simulates a restart of the extension at the given time
32
36
  async function restartBloomFilter(oldBloomFilter, { now, ...options }) {
33
- await Promise.all(oldBloomFilter.generations.map((gen) => gen.flush()));
37
+ await flushToDisk(oldBloomFilter);
34
38
  const uut = newBloomFilter(options);
35
39
  await uut.ready(now);
36
40
  return uut;
@@ -115,4 +119,65 @@ describe('#BloomFilter', function () {
115
119
  });
116
120
  });
117
121
  });
122
+
123
+ describe('#ready (cleanup of the database)', function () {
124
+ describe('with two generations on disk', function () {
125
+ const rotationIntervalInMs = 30 * DAY;
126
+ const options = { maxGenerations: 2, rotationIntervalInMs };
127
+ let now;
128
+ let uut;
129
+ let keysOfGen2;
130
+
131
+ beforeEach(async function () {
132
+ now = Date.now();
133
+ uut = newBloomFilter(options);
134
+ await uut.ready(now);
135
+ await uut.add('foo');
136
+
137
+ uut = await restartBloomFilter(uut, {
138
+ now: now + rotationIntervalInMs + DAY,
139
+ ...options,
140
+ });
141
+ await uut.add('bar');
142
+ await flushToDisk(uut);
143
+
144
+ const keys = await database.keys();
145
+ keysOfGen2 = keys.filter((key) => !key.includes(`|${now}|`));
146
+ expect(keys).to.have.lengthOf(2);
147
+ expect(keysOfGen2).to.have.lengthOf(1);
148
+ });
149
+
150
+ it('should delete the keys of a generation that was rotated out', async function () {
151
+ // The third generation starts. Two generations are the limit.
152
+ uut = await restartBloomFilter(uut, {
153
+ now: now + 2 * rotationIntervalInMs + 2 * DAY,
154
+ ...options,
155
+ });
156
+
157
+ expect(uut.generations).to.have.lengthOf(2);
158
+ expect(await database.keys()).to.eql(keysOfGen2);
159
+ });
160
+
161
+ it('should delete all generations that are too old', async function () {
162
+ // Both generations are older than their maximum age (two intervals).
163
+ uut = await restartBloomFilter(uut, {
164
+ now: now + 10 * rotationIntervalInMs,
165
+ ...options,
166
+ });
167
+
168
+ expect(uut.generations).to.have.lengthOf(1);
169
+ expect(await database.keys()).to.eql([]);
170
+ });
171
+ });
172
+
173
+ it('should delete keys from an old version and corrupted keys', async function () {
174
+ await database.set('bf|test|v0|123|some-shard', 'old version');
175
+ await database.set('bf|test|v1|no-timestamp|some-shard', 'corrupted');
176
+
177
+ const uut = newBloomFilter();
178
+ await uut.ready();
179
+
180
+ expect(await database.keys()).to.eql([]);
181
+ });
182
+ });
118
183
  });
@@ -9,6 +9,7 @@ import './patterns.spec.js';
9
9
  import './patterns-updater.spec.js';
10
10
  import './job-scheduler.spec.js';
11
11
  import './bloom-filters.spec.js';
12
+ import './persisted-bitarray.spec.js';
12
13
  import './country-provider.spec.js';
13
14
  import './persisted-hashes.spec.js';
14
15
  import './doublefetch-unbreak.spec.js';
@@ -0,0 +1,35 @@
1
+ /**
2
+ * WhoTracks.Me
3
+ * https://whotracks.me/
4
+ *
5
+ * Copyright 2017-present Ghostery GmbH. All rights reserved.
6
+ *
7
+ * This Source Code Form is subject to the terms of the Mozilla Public
8
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
9
+ * file, You can obtain one at http://mozilla.org/MPL/2.0
10
+ */
11
+
12
+ import { expect } from 'chai';
13
+
14
+ import PersistedBitarray from '../src/persisted-bitarray.js';
15
+ import InMemoryDatabase from './helpers/in-memory-database.js';
16
+
17
+ describe('#PersistedBitarray', function () {
18
+ let database;
19
+
20
+ beforeEach(function () {
21
+ database = new InMemoryDatabase();
22
+ });
23
+
24
+ describe('#ready (cleanup of the database)', function () {
25
+ it('should delete keys that do not match the shard configuration', async function () {
26
+ await database.set('arr|test|v0|0', 'shard from an old version');
27
+
28
+ const uut = new PersistedBitarray({ database, name: 'test', size: 1024 });
29
+ await uut.ready();
30
+ await new Promise((resolve) => setTimeout(resolve, 0));
31
+
32
+ expect(await database.keys()).to.eql([]);
33
+ });
34
+ });
35
+ });