@@ -566,60 +566,6 @@ function tryGetCachedValue<TKey extends OnyxKey>(key: TKey): OnyxValue<OnyxKey>
566566 return val ;
567567}
568568
569- /**
570- * Utility function to preserve object references for unchanged items in collection operations.
571- * Compares new values with cached values using deep equality and preserves references when data is identical.
572- * @returns The preserved collection with unchanged references maintained
573- */
574- function preserveCollectionReferences ( keyValuePairs : StorageKeyValuePair [ ] ) : OnyxInputKeyValueMapping {
575- const preservedCollection : OnyxInputKeyValueMapping = { } ;
576-
577- keyValuePairs . forEach ( ( [ key , value ] ) => {
578- const cachedValue = cache . get ( key , false ) ;
579-
580- // If no cached value exists, we need to add the new value (skip expensive deep equality check)
581- // Use deep equality check to preserve references for unchanged items
582- if ( cachedValue !== undefined && deepEqual ( value , cachedValue ) ) {
583- // Keep the existing reference
584- preservedCollection [ key ] = cachedValue ;
585- } else {
586- // Update cache only for changed items
587- cache . set ( key , value ) ;
588- preservedCollection [ key ] = value ;
589- }
590- } ) ;
591-
592- return preservedCollection ;
593- }
594-
595- /**
596- * Utility function for merge operations that preserves references after cache merge has been performed.
597- * Compares merged values with original cached values and preserves references when data is unchanged.
598- * @returns The preserved collection with unchanged references maintained
599- */
600- function preserveCollectionReferencesAfterMerge (
601- collection : Record < string , OnyxValue < OnyxKey > > ,
602- originalCachedValues : Record < string , OnyxValue < OnyxKey > > ,
603- ) : Record < string , OnyxValue < OnyxKey > > {
604- const preservedCollection : Record < string , OnyxValue < OnyxKey > > = { } ;
605-
606- Object . keys ( collection ) . forEach ( ( key ) => {
607- const newMergedValue = cache . get ( key , false ) ;
608- const originalValue = originalCachedValues [ key ] ;
609-
610- // Use deep equality check to preserve references for unchanged items
611- if ( originalValue !== undefined && deepEqual ( newMergedValue , originalValue ) ) {
612- // Keep the existing reference and update cache
613- preservedCollection [ key ] = originalValue ;
614- cache . set ( key , originalValue ) ;
615- } else {
616- preservedCollection [ key ] = newMergedValue ;
617- }
618- } ) ;
619-
620- return preservedCollection ;
621- }
622-
623569function getCachedCollection < TKey extends CollectionKeyBase > ( collectionKey : TKey , collectionMemberKeys ?: string [ ] ) : NonNullable < OnyxCollection < KeyValueMapping [ TKey ] > > {
624570 // Use optimized collection data retrieval when cache is populated
625571 const collectionData = cache . getCollectionData ( collectionKey ) ;
@@ -1507,10 +1453,9 @@ function setCollectionWithRetry<TKey extends CollectionKeyBase>({collectionKey,
15071453 const keyValuePairs = OnyxUtils . prepareKeyValuePairsForStorage ( mutableCollection , true , undefined , true ) ;
15081454 const previousCollection = OnyxUtils . getCachedCollection ( collectionKey ) ;
15091455
1510- // Preserve references for unchanged items in setCollection
1511- const preservedCollection = OnyxUtils . preserveCollectionReferences ( keyValuePairs ) ;
1456+ keyValuePairs . forEach ( ( [ key , value ] ) => cache . set ( key , value ) ) ;
15121457
1513- const updatePromise = OnyxUtils . scheduleNotifyCollectionSubscribers ( collectionKey , preservedCollection , previousCollection ) ;
1458+ const updatePromise = OnyxUtils . scheduleNotifyCollectionSubscribers ( collectionKey , mutableCollection , previousCollection ) ;
15141459
15151460 return Storage . multiSet ( keyValuePairs )
15161461 . catch ( ( error ) => OnyxUtils . retryOperation ( error , setCollectionWithRetry , { collectionKey, collection} , retryAttempt ) )
@@ -1634,21 +1579,10 @@ function mergeCollectionWithPatches<TKey extends CollectionKeyBase>(
16341579 const finalMergedCollection = { ...existingKeyCollection , ...newCollection } ;
16351580
16361581 // Prefill cache if necessary by calling get() on any existing keys and then merge original data to cache
1637- // and update all subscribers with reference preservation for unchanged items
1582+ // and update all subscribers
16381583 const promiseUpdate = previousCollectionPromise . then ( ( previousCollection ) => {
1639- // Capture the original cached values before merging
1640- const originalCachedValues : Record < string , OnyxValue < OnyxKey > > = { } ;
1641- Object . keys ( finalMergedCollection ) . forEach ( ( key ) => {
1642- originalCachedValues [ key ] = cache . get ( key , false ) ;
1643- } ) ;
1644-
1645- // Then merge all the data into cache as normal
16461584 cache . merge ( finalMergedCollection ) ;
1647-
1648- // Finally, preserve references for items that didn't actually change
1649- const preservedCollection = preserveCollectionReferencesAfterMerge ( finalMergedCollection , originalCachedValues ) ;
1650-
1651- return scheduleNotifyCollectionSubscribers ( collectionKey , preservedCollection , previousCollection ) ;
1585+ return scheduleNotifyCollectionSubscribers ( collectionKey , finalMergedCollection , previousCollection ) ;
16521586 } ) ;
16531587
16541588 return Promise . all ( promises )
@@ -1712,10 +1646,9 @@ function partialSetCollection<TKey extends CollectionKeyBase>({collectionKey, co
17121646 const previousCollection = getCachedCollection ( collectionKey , existingKeys ) ;
17131647 const keyValuePairs = prepareKeyValuePairsForStorage ( mutableCollection , true , undefined , true ) ;
17141648
1715- // Preserve references for unchanged items in partialSetCollection
1716- const preservedCollection = preserveCollectionReferences ( keyValuePairs ) ;
1649+ keyValuePairs . forEach ( ( [ key , value ] ) => cache . set ( key , value ) ) ;
17171650
1718- const updatePromise = scheduleNotifyCollectionSubscribers ( collectionKey , preservedCollection , previousCollection ) ;
1651+ const updatePromise = scheduleNotifyCollectionSubscribers ( collectionKey , mutableCollection , previousCollection ) ;
17191652
17201653 return Storage . multiSet ( keyValuePairs )
17211654 . catch ( ( error ) => retryOperation ( error , partialSetCollection , { collectionKey, collection} , retryAttempt ) )
@@ -1797,8 +1730,6 @@ const OnyxUtils = {
17971730 updateSnapshots,
17981731 mergeCollectionWithPatches,
17991732 partialSetCollection,
1800- preserveCollectionReferences,
1801- preserveCollectionReferencesAfterMerge,
18021733 logKeyChanged,
18031734 logKeyRemoved,
18041735 setWithRetry,
0 commit comments