Skip to content

Commit

Permalink
Merge pull request #45529 from Expensify/neil-getTransactionReportNam…
Browse files Browse the repository at this point in the history
…e-optimize

Avoid unnecessary expensive call to getTransactionDetails
  • Loading branch information
mountiny authored Jul 19, 2024
2 parents 5cff64e + 59c7221 commit 3951e36
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions scripts/symbolicate-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (Object.keys(argsMap).length === 0 || argsMap.help !== undefined) {
Logger.log('Options:');
Logger.log(' --profile=<filename> The .cpuprofile file to symbolicate');
Logger.log(' --platform=<ios|android> The platform for which the source map was uploaded');
Logger.log(' --gh-token Token to use for requests send to the GitHub API. By default tries to pick up from the environment variable GITHUB_TOKEN');
Logger.log(' --ghToken Token to use for requests send to the GitHub API. By default tries to pick up from the environment variable GITHUB_TOKEN');
Logger.log(' --help Display this help message');
process.exit(0);
}
Expand All @@ -53,7 +53,7 @@ if (argsMap.platform === undefined) {

const githubToken = argsMap.ghToken ?? process.env.GITHUB_TOKEN;
if (githubToken === undefined) {
Logger.error('No GitHub token provided. Either set a GITHUB_TOKEN environment variable or pass it using --gh-token');
Logger.error('No GitHub token provided. Either set a GITHUB_TOKEN environment variable or pass it using --ghToken');
process.exit(1);
}

Expand Down
31 changes: 16 additions & 15 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2958,16 +2958,17 @@ function getTransactionReportName(reportAction: OnyxEntry<ReportAction | Optimis
return Localize.translateLocal('iou.fieldPending');
}

const transactionDetails = getTransactionDetails(transaction);
if (ReportActionsUtils.isSentMoneyReportAction(reportAction)) {
return getIOUReportActionDisplayMessage(reportAction as ReportAction, transaction);
}

const formattedAmount = CurrencyUtils.convertToDisplayString(transactionDetails?.amount ?? 0, transactionDetails?.currency) ?? '';
const comment = (!TransactionUtils.isMerchantMissing(transaction) ? transactionDetails?.merchant : transactionDetails?.comment) ?? '';
const report = getReportOrDraftReport(transaction?.reportID);
const amount = TransactionUtils.getAmount(transaction, !isEmptyObject(report) && isExpenseReport(report)) ?? 0;
const formattedAmount = CurrencyUtils.convertToDisplayString(amount, TransactionUtils.getCurrency(transaction)) ?? '';
const comment = (!TransactionUtils.isMerchantMissing(transaction) ? TransactionUtils.getMerchant(transaction) : TransactionUtils.getDescription(transaction)) ?? '';
if (ReportActionsUtils.isTrackExpenseAction(reportAction)) {
return Localize.translateLocal('iou.threadTrackReportName', {formattedAmount, comment});
}
if (ReportActionsUtils.isSentMoneyReportAction(reportAction)) {
return getIOUReportActionDisplayMessage(reportAction as ReportAction, transaction);
}
return Localize.translateLocal('iou.threadExpenseReportName', {formattedAmount, comment});
}

Expand Down Expand Up @@ -3013,9 +3014,9 @@ function getReportPreviewMessage(
return Localize.translateLocal('iou.receiptMissingDetails');
}

const transactionDetails = getTransactionDetails(linkedTransaction);
const formattedAmount = CurrencyUtils.convertToDisplayString(transactionDetails?.amount ?? 0, transactionDetails?.currency);
return Localize.translateLocal('iou.didSplitAmount', {formattedAmount, comment: transactionDetails?.comment ?? ''});
const amount = TransactionUtils.getAmount(linkedTransaction, !isEmptyObject(report) && isExpenseReport(report)) ?? 0;
const formattedAmount = CurrencyUtils.convertToDisplayString(amount, TransactionUtils.getCurrency(linkedTransaction)) ?? '';
return Localize.translateLocal('iou.didSplitAmount', {formattedAmount, comment: TransactionUtils.getDescription(linkedTransaction) ?? ''});
}
}

Expand All @@ -3035,9 +3036,9 @@ function getReportPreviewMessage(
return Localize.translateLocal('iou.receiptMissingDetails');
}

const transactionDetails = getTransactionDetails(linkedTransaction);
const formattedAmount = CurrencyUtils.convertToDisplayString(transactionDetails?.amount ?? 0, transactionDetails?.currency);
return Localize.translateLocal('iou.trackedAmount', {formattedAmount, comment: transactionDetails?.comment ?? ''});
const amount = TransactionUtils.getAmount(linkedTransaction, !isEmptyObject(report) && isExpenseReport(report)) ?? 0;
const formattedAmount = CurrencyUtils.convertToDisplayString(amount, TransactionUtils.getCurrency(linkedTransaction)) ?? '';
return Localize.translateLocal('iou.trackedAmount', {formattedAmount, comment: TransactionUtils.getDescription(linkedTransaction) ?? ''});
}
}

Expand Down Expand Up @@ -6416,8 +6417,8 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry<ReportAction>,
return Localize.translateLocal(translationKey, {amount: formattedAmount, payer: ''});
}

const transactionDetails = getTransactionDetails(!isEmptyObject(transaction) ? transaction : undefined);
const formattedAmount = CurrencyUtils.convertToDisplayString(transactionDetails?.amount ?? 0, transactionDetails?.currency);
const amount = TransactionUtils.getAmount(transaction, !isEmptyObject(iouReport) && isExpenseReport(iouReport)) ?? 0;
const formattedAmount = CurrencyUtils.convertToDisplayString(amount, TransactionUtils.getCurrency(transaction)) ?? '';
const isRequestSettled = isSettled(originalMessage?.IOUReportID);
const isApproved = isReportApproved(iouReport);
if (isRequestSettled) {
Expand All @@ -6439,7 +6440,7 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry<ReportAction>,
}
return Localize.translateLocal(translationKey, {
formattedAmount,
comment: transactionDetails?.comment ?? '',
comment: TransactionUtils.getDescription(transaction) ?? '',
});
}

Expand Down

0 comments on commit 3951e36

Please sign in to comment.