Skip to content

Remove shouldRetry and canCancel now that deprecatedAPI is gone #19675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ const CONST = {
MAX_PENDING_TIME_MS: 10 * 1000,
COMMAND: {
RECONNECT_APP: 'ReconnectApp',
LOG: 'Log',
},
},
DEFAULT_TIME_ZONE: {automatic: true, selected: 'America/Los_Angeles'},
Expand Down
4 changes: 0 additions & 4 deletions src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ function write(command, apiCommandParameters = {}, onyxData = {}) {
command,
data: {
...data,

// This should be removed once we are no longer using deprecatedAPI https://github.com/Expensify/Expensify/issues/215650
shouldRetry: true,
canCancel: true,
},
..._.omit(onyxData, 'optimisticData'),
};
Expand Down
3 changes: 1 addition & 2 deletions src/libs/Authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function Authenticate(parameters) {
partnerUserSecret: parameters.partnerUserSecret,
twoFactorAuthCode: parameters.twoFactorAuthCode,
authToken: parameters.authToken,
shouldRetry: false,

// Force this request to be made because the network queue is paused when re-authentication is happening
forceNetworkRequest: true,
Expand Down Expand Up @@ -100,7 +99,7 @@ function reauthenticate(command = '') {
}

function getShortLivedAuthToken() {
return Network.post('OpenOldDotLink', {shouldRetry: false}).then((response) => {
return Network.post('OpenOldDotLink').then((response) => {
if (response && response.shortLivedAuthToken) {
return Promise.resolve(response.shortLivedAuthToken);
}
Expand Down
8 changes: 4 additions & 4 deletions src/libs/HttpUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ let reconnectAppCancellationController = new AbortController();
* @param {String} url
* @param {String} [method]
* @param {Object} [body]
* @param {Boolean} [canCancel]
* @param {String} [command]
* @returns {Promise}
*/
function processHTTPRequest(url, method = 'get', body = null, canCancel = true, command = '') {
function processHTTPRequest(url, method = 'get', body = null, command = '') {
let signal;
if (canCancel) {
// We don't want to cancel/abort any log requests so we leave the signal undefined if this is a Log command
if (command !== CONST.NETWORK.COMMAND.LOG) {
signal = command === CONST.NETWORK.COMMAND.RECONNECT_APP ? reconnectAppCancellationController.signal : cancellationController.signal;
}

Expand Down Expand Up @@ -136,7 +136,7 @@ function xhr(command, data, type = CONST.NETWORK.METHOD.POST, shouldUseSecure =
});

const url = ApiUtils.getCommandURL({shouldUseSecure, command});
return processHTTPRequest(url, type, formData, data.canCancel, command);
return processHTTPRequest(url, type, formData, command);
}

function cancelPendingReconnectAppRequest() {
Expand Down
7 changes: 3 additions & 4 deletions src/libs/Log.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import getPlatform from './getPlatform';
import pkg from '../../package.json';
import requireParameters from './requireParameters';
import * as Network from './Network';
import CONST from '../CONST';

let timeout = null;

Expand All @@ -16,12 +17,11 @@ let timeout = null;
* @returns {Promise}
*/
function LogCommand(parameters) {
const commandName = 'Log';
const commandName = CONST.NETWORK.COMMAND.LOG;
requireParameters(['logPacket', 'expensifyCashAppVersion'], parameters, commandName);

// Note: We are forcing Log to run since it requires no authToken and should only be queued when we are offline.
// Non-cancellable request: during logout, when requests are cancelled, we don't want to cancel any remaining logs
return Network.post(commandName, {...parameters, forceNetworkRequest: true, canCancel: false});
return Network.post(commandName, {...parameters, forceNetworkRequest: true});
}

/**
Expand All @@ -36,7 +36,6 @@ function LogCommand(parameters) {
function serverLoggingCallback(logger, params) {
const requestParams = params;
requestParams.shouldProcessImmediately = false;
requestParams.shouldRetry = false;
requestParams.expensifyCashAppVersion = `expensifyCash[${getPlatform()}]${pkg.version}`;
if (requestParams.parameters) {
requestParams.parameters = JSON.stringify(params.parameters);
Expand Down
4 changes: 2 additions & 2 deletions src/libs/Middleware/Logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import CONST from '../../CONST';
*/
function logRequestDetails(message, request, response = {}) {
// Don't log about log or else we'd cause an infinite loop
if (request.command === 'Log') {
if (request.command === CONST.NETWORK.COMMAND.LOG) {
return;
}

Expand Down Expand Up @@ -65,7 +65,7 @@ function Logging(response, request) {
} else if (error.message === CONST.ERROR.FAILED_TO_FETCH) {
// If the command that failed is Log it's possible that the next call to Log may also fail.
// This will lead to infinitely complex log params that can eventually crash the app.
if (request.command === 'Log') {
if (request.command === CONST.NETWORK.COMMAND.LOG) {
delete logParams.request;
}

Expand Down
8 changes: 2 additions & 6 deletions src/libs/Middleware/Reauthentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,9 @@ function Reauthentication(response, request, isFromSequentialQueue) {
// There are some API requests that should not be retried when there is an auth failure like
// creating and deleting logins. In those cases, they should handle the original response instead
// of the new response created by handleExpiredAuthToken.
const shouldRetry = lodashGet(request, 'data.shouldRetry');
// If the request was from the sequential queue we don't want to return, we want to run the reauthentication callback and retry the request
const apiRequestType = lodashGet(request, 'data.apiRequestType');
if (!shouldRetry && !apiRequestType) {
if (isFromSequentialQueue) {
return data;
}

if (!isFromSequentialQueue && !apiRequestType) {
if (request.resolve) {
request.resolve(data);
}
Expand Down
11 changes: 4 additions & 7 deletions src/libs/Network/MainQueue.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import _ from 'underscore';
import lodashGet from 'lodash/get';
import * as NetworkStore from './NetworkStore';
import * as SequentialQueue from './SequentialQueue';
import * as Request from '../Request';
import CONST from '../../CONST';

// Queue for network requests so we don't lose actions done by the user while offline
let networkRequestQueue = [];
Expand Down Expand Up @@ -56,17 +56,14 @@ function process() {
// Some requests should be retried and will end up here if the following conditions are met:
// - we are in the process of authenticating and the request is retryable (most are)
// - the request does not have forceNetworkRequest === true (this will trigger it to process immediately)
// - the request does not have shouldRetry === false (specified when we do not want to retry, defaults to true)
const requestsToProcessOnNextRun = [];

_.each(networkRequestQueue, (queuedRequest) => {
// Check if we can make this request at all and if we can't see if we should save it for the next run or chuck it into the ether
if (!canMakeRequest(queuedRequest)) {
const shouldRetry = lodashGet(queuedRequest, 'data.shouldRetry');
if (shouldRetry) {
// If we can't make the request because the sequential queue is running, let's wait until it finished then run the request instead of tossing it
if (SequentialQueue.isRunning) {
requestsToProcessOnNextRun.push(queuedRequest);
} else {
console.debug('Skipping request that should not be re-tried: ', {command: queuedRequest.command});
}
return;
}
Expand All @@ -84,7 +81,7 @@ function process() {
* Non-cancellable requests like Log would not be cleared
*/
function clear() {
networkRequestQueue = _.filter(networkRequestQueue, (request) => !request.data.canCancel);
_.filter(networkRequestQueue, (request) => request.command !== CONST.NETWORK.COMMAND.LOG);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/libs/Network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ function post(command, data = {}, type = CONST.NETWORK.METHOD.POST, shouldUseSec
// (e.g. any requests currently happening when the user logs out are cancelled)
request.data = {
...data,
shouldRetry: lodashGet(data, 'shouldRetry', true),
canCancel: lodashGet(data, 'canCancel', true),
appversion: pkg.version,
};

Expand Down
2 changes: 0 additions & 2 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ function signOut() {
partnerUserID: lodashGet(credentials, 'autoGeneratedLogin', ''),
partnerName: CONFIG.EXPENSIFY.PARTNER_NAME,
partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD,
shouldRetry: false,
});

Timing.clearData();
Expand Down Expand Up @@ -718,7 +717,6 @@ function authenticatePusher(socketID, channelName, callback) {
API.makeRequestWithSideEffects('AuthenticatePusher', {
socket_id: socketID,
channel_name: channelName,
shouldRetry: false,
forceNetworkRequest: true,
})
.then((response) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/NetworkTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ describe('NetworkTests', () => {
waitForPromisesToResolve()
.then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: true}))
.then(() => {
Network.post('Mock', {param1: 'value1', persist: true, shouldRetry: true});
Network.post('Mock', {param1: 'value1', persist: true});
return waitForPromisesToResolve();
})

Expand Down