Skip to content

Commit 64dc2df

Browse files
authored
Simplifies getting replay id attribute from data in queue (#1323)
1 parent 1b75622 commit 64dc2df

File tree

3 files changed

+5
-30
lines changed

3 files changed

+5
-30
lines changed

src/queue.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ class Queue {
102102
}
103103

104104
if (this.replayManager && data.body) {
105-
const replayId = _.getItemAttribute(data, 'replay_id');
105+
const replayId = data?.attributes?.find(
106+
(a) => a.key === 'replay_id',
107+
)?.value;
108+
106109
if (replayId) {
107110
item.replayId = this.replayManager.add(replayId, data.uuid);
108111
}

src/utility.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -623,16 +623,6 @@ function addItemAttributes(itemData, attributes) {
623623
}
624624
}
625625

626-
function getItemAttribute(itemData, key) {
627-
const attributes = itemData.attributes || [];
628-
for (let i = 0; i < attributes.length; ++i) {
629-
if (attributes[i].key === key) {
630-
return attributes[i].value;
631-
}
632-
}
633-
return undefined;
634-
}
635-
636626
/*
637627
* get - given an obj/array and a keypath, return the value at that keypath or
638628
* undefined if not possible.
@@ -787,7 +777,6 @@ export {
787777
addErrorContext,
788778
createTelemetryEvent,
789779
addItemAttributes,
790-
getItemAttribute,
791780
filterIp,
792781
formatArgsAsString,
793782
formatUrl,
@@ -814,5 +803,5 @@ export {
814803
stringify,
815804
maxByteSize,
816805
typeName,
817-
uuid4
806+
uuid4,
818807
};

test/utility.test.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -716,20 +716,3 @@ describe('addItemAttributes', function () {
716716
expect(item.data.attributes[0].value).to.equal('12345');
717717
});
718718
});
719-
720-
describe('getItemAttribute', function () {
721-
it('should skip undefined values', function () {
722-
const item = {
723-
data: {
724-
attributes: [
725-
{ key: 'replay_id', value: '12345' },
726-
{ key: 'session_id', value: '67890' },
727-
],
728-
},
729-
};
730-
let value = _.getItemAttribute(item.data, 'replay_id');
731-
expect(value).to.equal('12345');
732-
value = _.getItemAttribute(item.data, 'session_id');
733-
expect(value).to.equal('67890');
734-
});
735-
});

0 commit comments

Comments
 (0)