Skip to content

Commit

Permalink
chore(map): implement the same change using a Map
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dtfiedler authored and ppedziwiatr committed Nov 30, 2023
1 parent d3d2a92 commit 1a4cc94
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/core/modules/impl/ArweaveGatewayInteractionsLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,13 @@ export class ArweaveGatewayInteractionsLoader implements InteractionsLoader {
*/
interactions = interactions.filter((i) => i.node.block && i.node.block.id && i.node.block.height);
// deduplicate any interactions that may have been provided twice

Check failure on line 96 in src/core/modules/impl/ArweaveGatewayInteractionsLoader.ts

View workflow job for this annotation

GitHub Actions / build

Delete `·`
const deduplicatedInteractions = [];
// used to store block specific interactions
let tempInteractions = [];
let currentBlockHeight;
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);
const interactionMap = new Map();
for (const interaction of interactions) {
if (!interactionMap.has(interaction.node.id)) {

Check failure on line 99 in src/core/modules/impl/ArweaveGatewayInteractionsLoader.ts

View workflow job for this annotation

GitHub Actions / build

Delete `··`
interactionMap.set(interaction.node.id, interaction);

Check failure on line 100 in src/core/modules/impl/ArweaveGatewayInteractionsLoader.ts

View workflow job for this annotation

GitHub Actions / build

Replace `············` with `········`
}

Check failure on line 101 in src/core/modules/impl/ArweaveGatewayInteractionsLoader.ts

View workflow job for this annotation

GitHub Actions / build

Delete `··`
}
// flush remaining interactions to deduplicatedInteractions array
deduplicatedInteractions.push(...tempInteractions);
const deduplicatedInteractions = Array.from(interactionMap.values());

// note: this operation adds the "sortKey" to the interactions
let sortedInteractions = await this.sorter.sort(deduplicatedInteractions);
Expand Down

0 comments on commit 1a4cc94

Please sign in to comment.