@@ -1368,7 +1368,10 @@ function multiSetWithRetry(data: OnyxMultiSetInput, retryAttempt?: number): Prom
13681368
13691369 const keyValuePairsToSet = OnyxUtils . prepareKeyValuePairsForStorage ( newData , true ) ;
13701370
1371- // Group keys by collection for batched notification
1371+ // Group collection members by their parent collection key so each collection can be notified
1372+ // via a single batched keysChanged() call instead of one keyChanged() per member. For each
1373+ // collection, `partial` holds the new values being set and `previous` holds the cached values
1374+ // from before the set, which keysChanged() uses to skip subscribers whose value didn't change.
13721375 const collectionBatches = new Map < string , { partial : Record < string , OnyxValue < OnyxKey > > ; previous : Record < string , OnyxValue < OnyxKey > > } > ( ) ;
13731376 const nonCollectionPairs : Array < [ string , OnyxValue < OnyxKey > ] > = [ ] ;
13741377
@@ -1381,7 +1384,8 @@ function multiSetWithRetry(data: OnyxMultiSetInput, retryAttempt?: number): Prom
13811384
13821385 const collectionKey = OnyxKeys . getCollectionKey ( key ) ;
13831386 if ( collectionKey && OnyxKeys . isCollectionMemberKey ( collectionKey , key ) ) {
1384- // Capture the previous value before updating cache
1387+ // Capture the previous cached value BEFORE calling cache.set() so keysChanged()
1388+ // can diff old vs new per-member.
13851389 const previousValue = cache . get ( key ) ;
13861390 cache . set ( key , value ) ;
13871391
@@ -1393,17 +1397,19 @@ function multiSetWithRetry(data: OnyxMultiSetInput, retryAttempt?: number): Prom
13931397 batch . partial [ key ] = value ;
13941398 batch . previous [ key ] = previousValue ;
13951399 } else {
1400+ // Non-collection keys are notified individually — no batching.
13961401 cache . set ( key , value ) ;
13971402 nonCollectionPairs . push ( [ key , value ] ) ;
13981403 }
13991404 }
14001405
1401- // Notify collection subscribers once per collection (batched)
1406+ // One keysChanged() per collection — fires each collection-level subscriber once and lets
1407+ // keysChanged() internally decide which individual member subscribers need notification.
14021408 for ( const [ collectionKey , batch ] of collectionBatches ) {
14031409 keysChanged ( collectionKey as CollectionKeyBase , batch . partial , batch . previous ) ;
14041410 }
14051411
1406- // Notify non -collection key subscribers individually
1412+ // Non -collection keys go through the regular per- key notification path.
14071413 for ( const [ key , value ] of nonCollectionPairs ) {
14081414 keyChanged ( key , value ) ;
14091415 }
0 commit comments