Skip to content

Commit

Permalink
small refactor in funnel cursors filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Apr 18, 2024
1 parent d99b36b commit b2a8428
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
18 changes: 11 additions & 7 deletions packages/engine/paima-funnel/src/funnels/carp/funnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,21 @@ export class CarpFunnel extends BaseFunnel implements ChainFunnel {
const cursors = await getPaginationCursors.run(undefined, dbTx);

const extensions = sharedData.extensions
.filter(extensions => extensions.network === config.network)
.map(extension => extension.cdeId);

for (const cursor of cursors) {
// TODO: performance concern? but not likely
if (extensions.find(cdeId => cdeId === cursor.cde_id))
.filter(extensions => extensions.network === chainName)
.map(extension => extension.cdeId)
.reduce((set, cdeId) => {
set.add(cdeId);
return set;
}, new Set());

cursors
.filter(cursor => extensions.has(cursor.cde_id))
.forEach(cursor => {
newEntry.updateCursor(cursor.cde_id, {
cursor: cursor.cursor,
finished: cursor.finished,
});
}
});

return newEntry;
})();
Expand Down
16 changes: 10 additions & 6 deletions packages/engine/paima-funnel/src/funnels/mina/funnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,20 @@ export class MinaFunnel extends BaseFunnel implements ChainFunnel {

const extensions = sharedData.extensions
.filter(extensions => extensions.network === chainName)
.map(extension => extension.cdeId);

for (const cursor of cursors) {
// TODO: performance concern? but not likely
if (extensions.find(cdeId => cdeId === cursor.cde_id))
.map(extension => extension.cdeId)
.reduce((set, cdeId) => {
set.add(cdeId);
return set;
}, new Set());

cursors
.filter(cursor => extensions.has(cursor.cde_id))
.forEach(cursor => {
newEntry.updateCursor(cursor.cde_id, {
cursor: cursor.cursor,
finished: cursor.finished,
});
}
});

return newEntry;
})();
Expand Down

0 comments on commit b2a8428

Please sign in to comment.