Skip to content

Commit e0dbc87

Browse files
committed
Synchronous functions don't need async
This just add overhead, especially when called in loops.
1 parent 1aa1870 commit e0dbc87

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

redis/paymentCache.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ interface GroupedPaymentsAndInfoObject {
6969
info: AddressPaymentInfo
7070
}
7171

72-
export const generatePaymentFromTx = async (tx: TransactionsWithPaybuttonsAndPrices): Promise<Payment> => {
72+
export const generatePaymentFromTx = (tx: TransactionsWithPaybuttonsAndPrices): Payment => {
7373
const values = getTransactionValue(tx)
7474
let buttonDisplayDataList: Array<{ name: string, id: string}> = []
7575
if (tx.address.paybuttons !== undefined) {
@@ -97,7 +97,7 @@ export const generatePaymentFromTx = async (tx: TransactionsWithPaybuttonsAndPri
9797
}
9898
}
9999

100-
export const generatePaymentFromTxWithInvoices = async (tx: TransactionWithAddressAndPricesAndInvoices, userId?: string): Promise<Payment> => {
100+
export const generatePaymentFromTxWithInvoices = (tx: TransactionWithAddressAndPricesAndInvoices, userId?: string): Payment => {
101101
const values = getTransactionValue(tx)
102102
let buttonDisplayDataList: Array<{ name: string, id: string}> = []
103103
if (tx.address.paybuttons !== undefined) {
@@ -141,7 +141,7 @@ export const generateAndCacheGroupedPaymentsAndInfoForAddress = async (address:
141141
for (const tx of batch) {
142142
balance = balance.plus(tx.amount)
143143
if (tx.amount.gt(0)) {
144-
const payment = await generatePaymentFromTx(tx)
144+
const payment = generatePaymentFromTx(tx)
145145
paymentList.push(payment)
146146
paymentCount++
147147
}
@@ -235,7 +235,7 @@ const cacheGroupedPaymentsAppend = async (paymentsGroupedByKey: KeyValueT<Paymen
235235
export const cacheManyTxs = async (txs: TransactionsWithPaybuttonsAndPrices[]): Promise<void> => {
236236
const zero = new Prisma.Decimal(0)
237237
for (const tx of txs.filter(tx => tx.amount > zero)) {
238-
const payment = await generatePaymentFromTx(tx)
238+
const payment = generatePaymentFromTx(tx)
239239
if (payment.values.usd !== new Prisma.Decimal(0)) {
240240
const paymentsGroupedByKey = getPaymentsByWeek(tx.address.address, [payment])
241241
void await cacheGroupedPaymentsAppend(paymentsGroupedByKey)

services/transactionService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ export async function fetchAllPaymentsByUserIdWithPagination (
10951095
for (let index = 0; index < transactions.length; index++) {
10961096
const tx = transactions[index]
10971097
if (Number(tx.amount) > 0) {
1098-
const payment = await generatePaymentFromTxWithInvoices(tx as unknown as TransactionWithAddressAndPricesAndInvoices, userId)
1098+
const payment = generatePaymentFromTxWithInvoices(tx as unknown as TransactionWithAddressAndPricesAndInvoices, userId)
10991099
transformedData.push(payment)
11001100
}
11011101
}

0 commit comments

Comments
 (0)