Skip to content

Commit 2fa9007

Browse files
committed
Use .find(...) for performance
1 parent 519a39d commit 2fa9007

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

library/agent/InspectionStatistics.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,16 @@ export class InspectionStatistics {
231231
this.ipAddresses.total += 1;
232232
}
233233

234-
const blockingMatches = matches.filter((match) => !match.monitor);
235-
if (blockingMatches.length > 0) {
234+
const blockingMatch = matches.find((match) => !match.monitor);
235+
if (blockingMatch) {
236236
this.ipAddresses.blocked += 1;
237237
}
238238

239239
matches.forEach((match) => {
240240
if (!this.ipAddresses.breakdown[match.key]) {
241241
this.ipAddresses.breakdown[match.key] = { total: 0, blocked: 0 };
242242
}
243+
243244
this.ipAddresses.breakdown[match.key].total += 1;
244245

245246
if (!match.monitor) {
@@ -253,15 +254,16 @@ export class InspectionStatistics {
253254
this.userAgents.total += 1;
254255
}
255256

256-
const blockingMatches = matches.filter((match) => !match.monitor);
257-
if (blockingMatches.length > 0) {
257+
const blockingMatch = matches.find((match) => !match.monitor);
258+
if (blockingMatch) {
258259
this.userAgents.blocked += 1;
259260
}
260261

261262
matches.forEach((match) => {
262263
if (!this.userAgents.breakdown[match.key]) {
263264
this.userAgents.breakdown[match.key] = { total: 0, blocked: 0 };
264265
}
266+
265267
this.userAgents.breakdown[match.key].total += 1;
266268

267269
if (!match.monitor) {

0 commit comments

Comments
 (0)