Skip to content

Commit 2f9fb8a

Browse files
committed
Tighten comments to <= 3 lines
1 parent 1764d2c commit 2f9fb8a

2 files changed

Lines changed: 17 additions & 32 deletions

File tree

lib/OnyxUtils.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,17 +1598,9 @@ function mergeCollectionWithPatches<TKey extends CollectionKeyBase>(
15981598
// finalMergedCollection contains all the keys that were merged, without the keys of incompatible updates
15991599
const finalMergedCollection = {...existingKeyCollection, ...newCollection};
16001600

1601-
// Pre-warm cache for any existing storage keys that aren't yet in cache so the subsequent
1602-
// cache.merge() merges the new delta into the real previous storage value (rather than
1603-
// starting from `undefined` and dropping the existing keys).
1604-
//
1605-
// Fast path: when every existingKey is already in cache, skip the pre-warm entirely. This
1606-
// preserves the original promise-chain depth and the subscriber-callback timing that
1607-
// dependent tests rely on.
1608-
//
1609-
// Slow path: when at least one existingKey is a cache miss, use multiGet — it batches the
1610-
// missing keys into a single Storage.multiGet call (vs. N parallel get() invocations) and
1611-
// writes the storage values back to cache before resolving.
1601+
// Pre-warm cache for cache-miss existingKeys so cache.merge() merges the new delta into
1602+
// the real previous storage value. Fast path (all warm) skips the pre-warm to preserve
1603+
// promise-chain depth; slow path batches the misses into one Storage.multiGet.
16121604
const hasColdExistingKey = existingKeys.some((key) => !cache.hasCacheForKey(key));
16131605
// Swallow pre-warm read failures so a transient Storage.multiGet rejection doesn't
16141606
// skip the cache.merge() + keysChanged() below. Subscribers still see the merge even

tests/unit/onyxUtilsTest.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -921,10 +921,9 @@ describe('OnyxUtils', () => {
921921
});
922922

923923
describe('mergeCollection pre-warm', () => {
924-
// The retryOperation describe block above mutates StorageMock.setItem (and never restores it),
925-
// so by the time we run, setItem may be a rejecting mock from a prior test. Capture pristine
926-
// references at file-load time and restore them in beforeEach so our seeding via Onyx.set
927-
// actually reaches the in-memory storage provider.
924+
// retryOperation tests above replace StorageMock methods without restoring them, leaving
925+
// rejecting mocks behind. Capture pristine refs at file-load time and restore in beforeEach
926+
// so our Onyx.set seeding actually reaches the in-memory storage provider.
928927
const pristineSetItem = StorageMock.setItem;
929928
const pristineMultiSet = StorageMock.multiSet;
930929
const pristineMultiGet = StorageMock.multiGet;
@@ -939,11 +938,9 @@ describe('OnyxUtils', () => {
939938
StorageMock.multiMerge = pristineMultiMerge;
940939
});
941940

942-
// Make a key "cold" — value evicted from cache but the key is still tracked as persisted.
943-
// OnyxCache.drop also removes the key from `storageKeys`, which would cause getAllKeys() to
944-
// miss it (unless the entire storageKeys set is empty, in which case the function falls back
945-
// to Storage.getAllKeys). To reliably hit the cold-but-persisted state regardless of how many
946-
// other keys remain in cache, we re-register the key as known after dropping its value.
941+
// Make a key "cold" — value evicted from cache but still tracked as persisted. OnyxCache.drop
942+
// also removes the key from `storageKeys`, so we re-register it afterwards to reliably hit
943+
// the cold-but-persisted state regardless of getAllKeys()'s fallback path.
947944
const evictFromCache = (...keys: string[]) => {
948945
for (const key of keys) {
949946
OnyxCache.drop(key);
@@ -1103,10 +1100,9 @@ describe('OnyxUtils', () => {
11031100
await Onyx.set(coldMemberKey, {value: 'persisted'});
11041101
evictFromCache(coldMemberKey);
11051102

1106-
// Connect the subscriber and flush its initial data load FIRST, before installing
1107-
// the rejecting mock. Otherwise the connect's getCollectionDataAndSendAsObject path
1108-
// (whose multiGet call has no .catch) would consume the mockRejectedValueOnce and
1109-
// leak an unhandled rejection — not the merge pre-warm we're actually exercising.
1103+
// Connect and flush the subscriber's initial load BEFORE installing the rejecting mock —
1104+
// otherwise the connect's own multiGet (no .catch) consumes the mockRejectedValueOnce and
1105+
// leaks an unhandled rejection instead of exercising the merge pre-warm path.
11101106
const collectionCallback = jest.fn();
11111107
Onyx.connect({
11121108
key: collectionKey,
@@ -1134,10 +1130,9 @@ describe('OnyxUtils', () => {
11341130
expect(outerRejected).toBeNull();
11351131
expect(result).toBeUndefined();
11361132

1137-
// cache.merge() + keysChanged() must still have fired so subscribers see the merge.
1138-
// Use toMatchObject for the cold key because a successful concurrent read may have
1139-
// re-populated the persisted value into cache; what we care about is that the new
1140-
// {merged: true} delta is applied.
1133+
// cache.merge() + keysChanged() must still fire so subscribers see the merge. Use
1134+
// toMatchObject because a concurrent read may have re-populated the persisted value;
1135+
// what matters is that the new {merged: true} delta is applied on top.
11411136
expect(collectionCallback).toHaveBeenCalled();
11421137
const lastBroadcast = collectionCallback.mock.calls.at(-1)?.[0] as Record<string, unknown> | undefined;
11431138
expect(lastBroadcast?.[coldMemberKey]).toMatchObject({merged: true});
@@ -1146,10 +1141,8 @@ describe('OnyxUtils', () => {
11461141
});
11471142

11481143
describe('multiGet cache hit consistency', () => {
1149-
// Same suite-pollution guard as the pre-warm block above: capture pristine StorageMock
1150-
// references at file-load time and restore them in beforeEach. The retryOperation
1151-
// describe block above mutates StorageMock.setItem (and never restores it), so by the
1152-
// time we run, setItem may be a rejecting mock from a prior test.
1144+
// Same suite-pollution guard as the pre-warm block above — capture pristine StorageMock
1145+
// refs at file-load time and restore them in beforeEach, since retryOperation tests leak.
11531146
const pristineSetItem = StorageMock.setItem;
11541147
const pristineMultiGet = StorageMock.multiGet;
11551148
const pristineGetItem = StorageMock.getItem;

0 commit comments

Comments
 (0)