@@ -493,33 +493,39 @@ export function buildSlice({
493
493
updateProvidedBy : {
494
494
reducer (
495
495
draft ,
496
- action : PayloadAction < {
497
- queryCacheKey : QueryCacheKey
498
- providedTags : readonly FullTagDescription < string > [ ]
499
- } > ,
496
+ action : PayloadAction <
497
+ Array < {
498
+ queryCacheKey : QueryCacheKey
499
+ providedTags : readonly FullTagDescription < string > [ ]
500
+ } >
501
+ > ,
500
502
) {
501
- const { queryCacheKey, providedTags } = action . payload
502
-
503
- removeCacheKeyFromTags ( draft , queryCacheKey )
503
+ for ( const { queryCacheKey, providedTags } of action . payload ) {
504
+ removeCacheKeyFromTags ( draft , queryCacheKey )
504
505
505
- for ( const { type, id } of providedTags ) {
506
- const subscribedQueries = ( ( draft . tags [ type ] ??= { } ) [
507
- id || '__internal_without_id'
508
- ] ??= [ ] )
509
- const alreadySubscribed = subscribedQueries . includes ( queryCacheKey )
510
- if ( ! alreadySubscribed ) {
511
- subscribedQueries . push ( queryCacheKey )
506
+ for ( const { type, id } of providedTags ) {
507
+ const subscribedQueries = ( ( draft . tags [ type ] ??= { } ) [
508
+ id || '__internal_without_id'
509
+ ] ??= [ ] )
510
+ const alreadySubscribed =
511
+ subscribedQueries . includes ( queryCacheKey )
512
+ if ( ! alreadySubscribed ) {
513
+ subscribedQueries . push ( queryCacheKey )
514
+ }
512
515
}
513
- }
514
516
515
- // Remove readonly from the providedTags array
516
- draft . keys [ queryCacheKey ] =
517
- providedTags as FullTagDescription < string > [ ]
517
+ // Remove readonly from the providedTags array
518
+ draft . keys [ queryCacheKey ] =
519
+ providedTags as FullTagDescription < string > [ ]
520
+ }
518
521
} ,
519
- prepare : prepareAutoBatched < {
520
- queryCacheKey : QueryCacheKey
521
- providedTags : readonly FullTagDescription < string > [ ]
522
- } > ( ) ,
522
+ prepare :
523
+ prepareAutoBatched <
524
+ Array < {
525
+ queryCacheKey : QueryCacheKey
526
+ providedTags : readonly FullTagDescription < string > [ ]
527
+ } >
528
+ > ( ) ,
523
529
} ,
524
530
} ,
525
531
extraReducers ( builder ) {
@@ -550,21 +556,26 @@ export function buildSlice({
550
556
. addMatcher (
551
557
isAnyOf ( isFulfilled ( queryThunk ) , isRejectedWithValue ( queryThunk ) ) ,
552
558
( draft , action ) => {
553
- writeProvidedTagsForQuery ( draft , action )
559
+ writeProvidedTagsForQueries ( draft , [ action ] )
554
560
} ,
555
561
)
556
562
. addMatcher (
557
563
querySlice . actions . cacheEntriesUpserted . match ,
558
564
( draft , action ) => {
559
- for ( const { queryDescription : arg , value } of action . payload ) {
560
- const action : CalculateProvidedByAction = {
561
- type : 'UNKNOWN' ,
562
- payload : value ,
563
- meta : { requestStatus : 'fulfilled' , requestId : 'UNKNOWN' , arg } ,
564
- }
565
-
566
- writeProvidedTagsForQuery ( draft , action )
567
- }
565
+ const mockActions : CalculateProvidedByAction [ ] = action . payload . map (
566
+ ( { queryDescription, value } ) => {
567
+ return {
568
+ type : 'UNKNOWN' ,
569
+ payload : value ,
570
+ meta : {
571
+ requestStatus : 'fulfilled' ,
572
+ requestId : 'UNKNOWN' ,
573
+ arg : queryDescription ,
574
+ } ,
575
+ }
576
+ } ,
577
+ )
578
+ writeProvidedTagsForQueries ( draft , mockActions )
568
579
} ,
569
580
)
570
581
} ,
@@ -592,24 +603,24 @@ export function buildSlice({
592
603
delete draft . keys [ queryCacheKey ]
593
604
}
594
605
595
- function writeProvidedTagsForQuery (
606
+ function writeProvidedTagsForQueries (
596
607
draft : InvalidationState < string > ,
597
- action : CalculateProvidedByAction ,
608
+ actions : CalculateProvidedByAction [ ] ,
598
609
) {
599
- const providedTags = calculateProvidedByThunk (
600
- action ,
601
- 'providesTags' ,
602
- definitions ,
603
- assertTagType ,
604
- )
605
- const { queryCacheKey } = action . meta . arg
610
+ const providedByEntries = actions . map ( ( action ) => {
611
+ const providedTags = calculateProvidedByThunk (
612
+ action ,
613
+ 'providesTags' ,
614
+ definitions ,
615
+ assertTagType ,
616
+ )
617
+ const { queryCacheKey } = action . meta . arg
618
+ return { queryCacheKey, providedTags }
619
+ } )
606
620
607
621
invalidationSlice . caseReducers . updateProvidedBy (
608
622
draft ,
609
- invalidationSlice . actions . updateProvidedBy ( {
610
- queryCacheKey,
611
- providedTags,
612
- } ) ,
623
+ invalidationSlice . actions . updateProvidedBy ( providedByEntries ) ,
613
624
)
614
625
}
615
626
0 commit comments