Skip to content

Commit 48ced89

Browse files
committed
chore: proxy
1 parent d5e3060 commit 48ced89

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

packages/cubejs-backend-shared/src/decorators.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import crypto from 'crypto';
1+
import { asyncDebounce } from './promises';
22

33
/**
44
* Decorator version of asyncDebounce for methods and functions.
@@ -11,25 +11,10 @@ export function AsyncDebounce() {
1111
descriptor: PropertyDescriptor
1212
) {
1313
const originalMethod = descriptor.value;
14-
const cache = new Map<string, Promise<any>>();
15-
16-
descriptor.value = async function (...args: any[]) {
17-
const key = crypto.createHash('md5')
18-
.update(args.map((v) => JSON.stringify(v)).join(','))
19-
.digest('hex');
20-
21-
if (cache.has(key)) {
22-
return cache.get(key);
23-
}
24-
25-
try {
26-
const promise = originalMethod.apply(this, args);
27-
cache.set(key, promise);
28-
return await promise;
29-
} finally {
30-
cache.delete(key);
31-
}
32-
};
14+
15+
descriptor.value = asyncDebounce(async function (...args: any[]) {
16+
return originalMethod.apply(this, args);
17+
});
3318

3419
return descriptor;
3520
};

0 commit comments

Comments
 (0)