@@ -71,7 +71,6 @@ class DataLoader<K, V, C = K> {
7171
7272 // If there's nothing to load, resolve any cache hits and return early.
7373 if ( batch . keys . length === 0 ) {
74- resolveCacheHits ( batch ) ;
7574 return ;
7675 }
7776
@@ -125,9 +124,6 @@ class DataLoader<K, V, C = K> {
125124 ) ;
126125 }
127126
128- // Resolve all cache hits in the same micro-task as freshly loaded values.
129- resolveCacheHits ( batch ) ;
130-
131127 // Step through values, resolving or rejecting each Promise in the batch.
132128 for ( let i = 0 ; i < batch . callbacks . length ; i ++ ) {
133129 const value = values [ i ] ! ;
@@ -178,8 +174,6 @@ class DataLoader<K, V, C = K> {
178174 // Private: do not cache individual loads if the entire batch dispatch fails,
179175 // but still reject each request so they do not hang.
180176 private failedDispatch ( batch : Batch < K , V > , error : Error ) {
181- // Cache hits are resolved, even though the batch failed.
182- resolveCacheHits ( batch ) ;
183177 for ( let i = 0 ; i < batch . keys . length ; i ++ ) {
184178 this . clear ( batch . keys [ i ] ! ) ;
185179 batch . callbacks [ i ] ! . reject ( error ) ;
@@ -205,12 +199,7 @@ class DataLoader<K, V, C = K> {
205199 cacheKey = this . _cacheKeyFn ( key ) ;
206200 const cachedPromise = cacheMap . get ( cacheKey ) ;
207201 if ( cachedPromise ) {
208- const cacheHits = batch . cacheHits || ( batch . cacheHits = [ ] ) ;
209- return new Promise ( resolve => {
210- cacheHits . push ( ( ) => {
211- resolve ( cachedPromise ) ;
212- } ) ;
213- } ) ;
202+ return cachedPromise ;
214203 }
215204 }
216205
@@ -377,18 +366,8 @@ type Batch<K, V> = {
377366 resolve : ( value : V ) => void ;
378367 reject : ( error : Error ) => void ;
379368 } > ;
380- cacheHits ?: Array < ( ) => void > ;
381369} ;
382370
383- // Private: Resolves the Promises for any cache hits in this batch.
384- function resolveCacheHits < K , V > ( batch : Batch < K , V > ) {
385- if ( batch . cacheHits ) {
386- for ( let i = 0 ; i < batch . cacheHits . length ; i ++ ) {
387- batch . cacheHits [ i ] ! ( ) ;
388- }
389- }
390- }
391-
392371// Private: given the DataLoader's options, produce a valid max batch size.
393372function getValidMaxBatchSize < K , V , C > ( options ?: Options < K , V , C > ) : number {
394373 const shouldBatch = ! options || options . batch !== false ;
0 commit comments