@@ -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 ) ;
@@ -1634,21 +1580,10 @@ function mergeCollectionWithPatches<TKey extends CollectionKeyBase>(
16341580 const finalMergedCollection = { ...existingKeyCollection , ...newCollection } ;
16351581
16361582 // 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
1583+ // and update all subscribers
16381584 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
16461585 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 ) ;
1586+ return scheduleNotifyCollectionSubscribers ( collectionKey , finalMergedCollection , previousCollection ) ;
16521587 } ) ;
16531588
16541589 return Promise . all ( promises )
@@ -1712,10 +1647,9 @@ function partialSetCollection<TKey extends CollectionKeyBase>({collectionKey, co
17121647 const previousCollection = getCachedCollection ( collectionKey , existingKeys ) ;
17131648 const keyValuePairs = prepareKeyValuePairsForStorage ( mutableCollection , true , undefined , true ) ;
17141649
1715- // Preserve references for unchanged items in partialSetCollection
1716- const preservedCollection = preserveCollectionReferences ( keyValuePairs ) ;
1650+ keyValuePairs . forEach ( ( [ key , value ] ) => cache . set ( key , value ) ) ;
17171651
1718- const updatePromise = scheduleNotifyCollectionSubscribers ( collectionKey , preservedCollection , previousCollection ) ;
1652+ const updatePromise = scheduleNotifyCollectionSubscribers ( collectionKey , mutableCollection , previousCollection ) ;
17191653
17201654 return Storage . multiSet ( keyValuePairs )
17211655 . catch ( ( error ) => retryOperation ( error , partialSetCollection , { collectionKey, collection} , retryAttempt ) )
@@ -1797,8 +1731,6 @@ const OnyxUtils = {
17971731 updateSnapshots,
17981732 mergeCollectionWithPatches,
17991733 partialSetCollection,
1800- preserveCollectionReferences,
1801- preserveCollectionReferencesAfterMerge,
18021734 logKeyChanged,
18031735 logKeyRemoved,
18041736 setWithRetry,
0 commit comments