@whotracksme/reporting 5.1.33 → 5.1.35

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,27 @@
1
+ # v5.1.35 (Mon Nov 18 2024)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Request: keys pipeline picks a random tokens if too many [#131](https://github.com/whotracksme/webextension-packages/pull/131) ([@chrmod](https://github.com/chrmod))
6
+
7
+ #### Authors: 1
8
+
9
+ - Krzysztof Modras ([@chrmod](https://github.com/chrmod))
10
+
11
+ ---
12
+
13
+ # v5.1.34 (Thu Nov 14 2024)
14
+
15
+ #### 🐛 Bug Fix
16
+
17
+ - Request: fix token telemetry cleanup [#130](https://github.com/whotracksme/webextension-packages/pull/130) ([@chrmod](https://github.com/chrmod))
18
+
19
+ #### Authors: 1
20
+
21
+ - Krzysztof Modras ([@chrmod](https://github.com/chrmod))
22
+
23
+ ---
24
+
1
25
  # v5.1.33 (Tue Nov 12 2024)
2
26
 
3
27
  #### 🐛 Bug Fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whotracksme/reporting",
3
- "version": "5.1.33",
3
+ "version": "5.1.35",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "scripts": {
@@ -164,7 +164,7 @@ export default class CachedEntryPipeline {
164
164
  });
165
165
  // push first maxSending entries to input queue
166
166
  queuedForSending.splice(maxSending);
167
- queuedForSending.forEach((v) => this.input.pub(v));
167
+ queuedForSending.forEach((v) => this.processEntry.pub(v));
168
168
  // delete old entries
169
169
  this.db.bulkDelete(toBeDeleted);
170
170
  // check the cache for items to persist to the db.
@@ -21,6 +21,7 @@ const DEFAULT_CONFIG = {
21
21
  // key batches, max 450 messages/hour
22
22
  KEY_BATCH_INTERVAL: 80 * 1000,
23
23
  KEY_BATCH_SIZE: 10,
24
+ KEY_TOKENS_LIMIT: 512,
24
25
  // clean every 4 mins (activity triggered)
25
26
  CLEAN_INTERVAL: 4 * 60 * 1000,
26
27
  // batch size of incoming tokens
@@ -10,6 +10,7 @@
10
10
  */
11
11
 
12
12
  import CachedEntryPipeline from './cached-entry-pipeline.js';
13
+ import logger from '../../../logger.js';
13
14
 
14
15
  export function getSiteTokensMap(siteTokens, key) {
15
16
  let siteTokensMap = siteTokens[key];
@@ -84,12 +85,26 @@ export default class KeyPipeline extends CachedEntryPipeline {
84
85
  entry = [];
85
86
  groupedMessages.set(`${site}${extraKey}`, entry);
86
87
  }
88
+ let tokensToSend = Object.entries(tokens);
89
+
90
+ if (tokensToSend.length > this.options.KEY_TOKENS_LIMIT) {
91
+ logger.warn(
92
+ '[Request keys-pipeline]',
93
+ `too many tokens for site="${site}" key="${stats.key}" tracker=${stats.tracker}`,
94
+ `picking a random sample ${this.options.KEY_TOKENS_LIMIT} of ${tokensToSend.length}`,
95
+ );
96
+ tokensToSend = takeRandomSample(
97
+ Object.entries(tokens),
98
+ this.options.KEY_TOKENS_LIMIT,
99
+ );
100
+ }
101
+
87
102
  entry.push({
88
103
  ts: this.trustedClock.getTimeAsYYYYMMDD(),
89
104
  tracker: stats.tracker,
90
105
  key: stats.key,
91
106
  site,
92
- tokens: Object.entries(tokens),
107
+ tokens: tokensToSend,
93
108
  });
94
109
  });
95
110
  Object.keys(stats.sitesTokens).forEach(
@@ -108,3 +123,20 @@ export default class KeyPipeline extends CachedEntryPipeline {
108
123
  return Object.keys(entry.sitesTokens).length > 0;
109
124
  }
110
125
  }
126
+
127
+ function takeRandomSample(array, size) {
128
+ const shuffled = [...array];
129
+ let currentIndex = shuffled.length;
130
+
131
+ // Fisher-Yates Shuffle Algorithm
132
+ while (currentIndex !== 0) {
133
+ const randomIndex = Math.floor(Math.random() * currentIndex);
134
+ currentIndex--;
135
+
136
+ const temporaryValue = shuffled[currentIndex];
137
+ shuffled[currentIndex] = shuffled[randomIndex];
138
+ shuffled[randomIndex] = temporaryValue;
139
+ }
140
+
141
+ return shuffled.slice(0, size);
142
+ }