Skip to content

Commit 6fc70ed

Browse files
committed
Minor improvement and test fix
1 parent df729c3 commit 6fc70ed

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

lib/OnyxUtils.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -879,27 +879,27 @@ function retryOperation<TMethod extends typeof Onyx.set | typeof Onyx.multiSet |
879879
const storageErrors = ['quotaexceedederror', 'database or disk is full', 'disk I/O error', 'out of memory'];
880880
const isStorageCapacityError = storageErrors.includes(error?.name?.toLowerCase()) || storageErrors.some((message) => errorMessage?.includes(message));
881881

882-
if (isStorageCapacityError) {
883-
// Find the first key that we can remove that has no subscribers in our blocklist
884-
const keyForRemoval = cache.getKeyForEviction();
885-
if (!keyForRemoval) {
886-
// If we have no acceptable keys to remove then we are possibly trying to save mission critical data. If this is the case,
887-
// then we should stop retrying as there is not much the user can do to fix this. Instead of getting them stuck in an infinite loop we
888-
// will allow this write to be skipped.
889-
Logger.logAlert('Out of storage. But found no acceptable keys to remove.');
890-
return reportStorageQuota();
891-
}
892-
893-
// Remove the least recently viewed key that is not currently being accessed and retry.
894-
Logger.logInfo(`Out of storage. Evicting least recently accessed key (${keyForRemoval}) and retrying.`);
895-
reportStorageQuota();
896-
882+
if (!isStorageCapacityError) {
897883
// @ts-expect-error No overload matches this call.
898-
return remove(keyForRemoval).then(() => onyxMethod(...args));
884+
return onyxMethod(...args);
899885
}
900886

887+
// Find the first key that we can remove that has no subscribers in our blocklist
888+
const keyForRemoval = cache.getKeyForEviction();
889+
if (!keyForRemoval) {
890+
// If we have no acceptable keys to remove then we are possibly trying to save mission critical data. If this is the case,
891+
// then we should stop retrying as there is not much the user can do to fix this. Instead of getting them stuck in an infinite loop we
892+
// will allow this write to be skipped.
893+
Logger.logAlert('Out of storage. But found no acceptable keys to remove.');
894+
return reportStorageQuota();
895+
}
896+
897+
// Remove the least recently viewed key that is not currently being accessed and retry.
898+
Logger.logInfo(`Out of storage. Evicting least recently accessed key (${keyForRemoval}) and retrying.`);
899+
reportStorageQuota();
900+
901901
// @ts-expect-error No overload matches this call.
902-
return onyxMethod(...args);
902+
return remove(keyForRemoval).then(() => onyxMethod(...args));
903903
}
904904

905905
/**

tests/unit/cacheEvictionTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test('Cache eviction', () => {
4545
const setItemMock = jest.fn(originalSetItem).mockImplementationOnce(
4646
() =>
4747
new Promise((_resolve, reject) => {
48-
reject();
48+
reject(new Error('out of memory'));
4949
}),
5050
);
5151
StorageMock.setItem = setItemMock;

0 commit comments

Comments
 (0)