Skip to content

Commit

Permalink
Replace EE with requestDeduplicator
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaituVR committed Aug 2, 2023
1 parent 6f2649f commit 8b1fada
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/graphql/operations/votes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import graphqlFields from 'graphql-fields';
import db from '../../helpers/mysql';
import { buildWhereQuery, checkLimits, formatProposal, formatSpace, formatVote } from '../helpers';
import serve from '../../helpers/ee';
import serve from '../../helpers/requestDeduplicator';
import log from '../../helpers/log';
import { capture } from '@snapshot-labs/snapshot-sentry';

Expand Down
20 changes: 0 additions & 20 deletions src/helpers/ee.ts

This file was deleted.

22 changes: 22 additions & 0 deletions src/helpers/requestDeduplicator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { sha256 } from './utils';

const ongoingRequests = new Map();

export default async function serve(id, action, args) {
const key = sha256(id);
if (!ongoingRequests.has(key)) {
const requestPromise = action(...args)
.then(result => {
ongoingRequests.delete(key);
return result;
})
.catch(e => {
console.log('EventEmitter Error', e);
ongoingRequests.delete(key);
throw { error: true, e };
});
ongoingRequests.set(key, requestPromise);
}

return ongoingRequests.get(key);
}

0 comments on commit 8b1fada

Please sign in to comment.