chore(map): implement the same change using a Map
This improves complexity even further, and simplifies the implementation. The `Map` can be replaced an object, with some modification to the key check and array generation.
This commit is contained in:
@@ -94,25 +94,13 @@ export class ArweaveGatewayInteractionsLoader implements InteractionsLoader {
|
|||||||
*/
|
*/
|
||||||
interactions = interactions.filter((i) => i.node.block && i.node.block.id && i.node.block.height);
|
interactions = interactions.filter((i) => i.node.block && i.node.block.id && i.node.block.height);
|
||||||
// deduplicate any interactions that may have been provided twice
|
// deduplicate any interactions that may have been provided twice
|
||||||
const deduplicatedInteractions = [];
|
const interactionMap = new Map();
|
||||||
// used to store block specific interactions
|
for (const interaction of interactions) {
|
||||||
let tempInteractions = [];
|
if (!interactionMap.has(interaction.node.id)) {
|
||||||
let currentBlockHeight;
|
interactionMap.set(interaction.node.id, interaction);
|
||||||
for(const i of interactions){
|
|
||||||
// flush interactions to deduplicated
|
|
||||||
if(currentBlockHeight != i.node.block.height){
|
|
||||||
deduplicatedInteractions.push(...tempInteractions);
|
|
||||||
tempInteractions = [];
|
|
||||||
currentBlockHeight = i.node.block.height;
|
|
||||||
}
|
|
||||||
const interactonTxId = i.node.id;
|
|
||||||
const existingInteraction = temp.find((int) => int.node.id === interactonTxId);
|
|
||||||
if(!existingInteraction){
|
|
||||||
temp.push(i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// flush remaining interactions to deduplicatedInteractions array
|
const deduplicatedInteractions = Array.from(interactionMap.values());
|
||||||
deduplicatedInteractions.push(...tempInteractions);
|
|
||||||
|
|
||||||
// note: this operation adds the "sortKey" to the interactions
|
// note: this operation adds the "sortKey" to the interactions
|
||||||
let sortedInteractions = await this.sorter.sort(deduplicatedInteractions);
|
let sortedInteractions = await this.sorter.sort(deduplicatedInteractions);
|
||||||
|
|||||||
Reference in New Issue
Block a user