File tree Expand file tree Collapse file tree 1 file changed +5
-20
lines changed
packages/cubejs-backend-shared/src Expand file tree Collapse file tree 1 file changed +5
-20
lines changed Original file line number Diff line number Diff line change 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 } ;
You can’t perform that action at this time.
0 commit comments