|
1 | 1 | import { InternalPlugin } from '../InternalPlugin'; |
2 | 2 | import { |
3 | 3 | getResourceFileType, |
4 | | - isPutRumEventsCall, |
5 | | - shuffle |
| 4 | + isPutRumEventsCall |
6 | 5 | } from '../../utils/common-utils'; |
7 | 6 | import { ResourceEvent } from '../../events/resource-event'; |
8 | 7 | import { PERFORMANCE_RESOURCE_EVENT_TYPE } from '../utils/constant'; |
@@ -56,33 +55,27 @@ export class ResourcePlugin extends InternalPlugin { |
56 | 55 | }; |
57 | 56 |
|
58 | 57 | recordPerformanceEntries = (list: PerformanceEntryList) => { |
59 | | - const recordAll: PerformanceEntry[] = []; |
60 | | - const sample: PerformanceEntry[] = []; |
61 | | - |
62 | | - list.filter((e) => e.entryType === RESOURCE) |
63 | | - .filter((e) => !this.config.ignore(e)) |
64 | | - .forEach((event) => { |
65 | | - const { name, initiatorType } = |
66 | | - event as PerformanceResourceTiming; |
67 | | - const type = getResourceFileType(name, initiatorType); |
68 | | - if (this.config.recordAllTypes.includes(type)) { |
69 | | - recordAll.push(event); |
70 | | - } else if (this.config.sampleTypes.includes(type)) { |
71 | | - sample.push(event); |
72 | | - } |
73 | | - }); |
| 58 | + list.forEach((event) => { |
| 59 | + if (event.entryType !== RESOURCE || this.config.ignore(event)) { |
| 60 | + // ignore |
| 61 | + return; |
| 62 | + } |
74 | 63 |
|
75 | | - // Record all events for resources in recordAllTypes |
76 | | - recordAll.forEach((r) => |
77 | | - this.recordResourceEvent(r as PerformanceResourceTiming) |
78 | | - ); |
| 64 | + const { name, initiatorType } = event as PerformanceResourceTiming; |
| 65 | + const type = getResourceFileType(name, initiatorType); |
79 | 66 |
|
80 | | - // Record events from resources in sample until we hit the resource limit |
81 | | - shuffle(sample); |
82 | | - while (sample.length > 0 && this.eventCount < this.config.eventLimit) { |
83 | | - this.recordResourceEvent(sample.pop() as PerformanceResourceTiming); |
84 | | - this.eventCount++; |
85 | | - } |
| 67 | + if (this.config.recordAllTypes.includes(type)) { |
| 68 | + // Record all events for resources in recordAllTypes |
| 69 | + this.recordResourceEvent(event as PerformanceResourceTiming); |
| 70 | + } else if ( |
| 71 | + this.config.sampleTypes.includes(type) && |
| 72 | + this.eventCount < this.config.eventLimit |
| 73 | + ) { |
| 74 | + // Record sample types |
| 75 | + this.recordResourceEvent(event as PerformanceResourceTiming); |
| 76 | + this.eventCount++; |
| 77 | + } |
| 78 | + }); |
86 | 79 | }; |
87 | 80 |
|
88 | 81 | recordResourceEvent = ({ |
|
0 commit comments