fix(ArweaveGatewayInteractionsLoader): avoid processing duplicate interactions

This change ensures that interactions provided to `ArweaveGatewayInteractionsLoader` are deduplicated before processing. By doing it before `sortKey`'s you prevent duplicate computation of an async request.
This commit is contained in:
Dylan Fiedler
2023-11-28 15:04:57 -07:00
committed by just_ppe
parent 81d305fdb4
commit fb72af3025

View File

@@ -93,9 +93,18 @@ export class ArweaveGatewayInteractionsLoader implements InteractionsLoader {
* - we're removing all the interactions, that have null block data.
*/
interactions = interactions.filter((i) => i.node.block && i.node.block.id && i.node.block.height);
// dedeuplicate any interactions that may have been provided twice
const dedeuplicatedInteractions = []
for(const i of dedeuplicatedInteractions){
const interactonTxId = i.node.id;
const existingInteraction = dedeuplicatedInteractions.find((int) => int.node.id === interactonTxId);
if(!existingInteraction){
dedeuplicatedInteractions.push(i);
}
}
// note: this operation adds the "sortKey" to the interactions
let sortedInteractions = await this.sorter.sort(interactions);
let sortedInteractions = await this.sorter.sort(dedeuplicatedInteractions);
if (fromSortKey && toSortKey) {
sortedInteractions = sortedInteractions.filter((i) => {