lint, add and use BalanceLoggingView in BalanceResolver.balance

This commit is contained in:
einhornimmond 2024-06-19 11:27:46 +02:00
parent 91435656e0
commit 4f480faf75
4 changed files with 69 additions and 14 deletions

View File

@ -8,6 +8,7 @@ import { Resolver, Query, Ctx, Authorized } from 'type-graphql'
import { Balance } from '@model/Balance'
import { RIGHTS } from '@/auth/RIGHTS'
import { DecayLoggingView } from '@/logging/DecayLogging.view'
import { Context, getUser } from '@/server/context'
import { backendLogger as logger } from '@/server/logger'
import { calculateDecay } from '@/util/decay'
@ -15,7 +16,7 @@ import { calculateDecay } from '@/util/decay'
import { GdtResolver } from './GdtResolver'
import { getLastTransaction } from './util/getLastTransaction'
import { transactionLinkSummary } from './util/transactionLinkSummary'
import { DecayLoggingView } from '@/logging/DecayLogging.view'
import { BalanceLoggingView } from '@/logging/BalanceLogging.view'
@Resolver()
export class BalanceResolver {
@ -40,7 +41,11 @@ export class BalanceResolver {
? context.lastTransaction
: await getLastTransaction(user.id)
logger.info(`time for load lastTransaction from db (if not already done): ${new Date().getTime() - profilingTime.getTime()} ms`)
logger.info(
`time for load lastTransaction from db (if not already done): ${
new Date().getTime() - profilingTime.getTime()
} ms`,
)
profilingTime = new Date()
logger.debug(`lastTransaction=${lastTransaction}`)
@ -60,11 +65,13 @@ export class BalanceResolver {
context.transactionCount || context.transactionCount === 0
? context.transactionCount
: await dbTransaction.count({ where: { userId: user.id } })
logger.debug(`transactionCount=${count}`)
logger.info(`time for count transaction in db: ${new Date().getTime() - profilingTime.getTime()} ms`)
profilingTime = new Date()
logger.info(
`time for count transaction in db: ${new Date().getTime() - profilingTime.getTime()} ms`,
)
profilingTime = new Date()
const linkCount = await dbTransactionLink.count({
where: {
@ -75,7 +82,11 @@ export class BalanceResolver {
})
logger.debug(`linkCount=${linkCount}`)
logger.info(`time for count transaction links in db: ${new Date().getTime() - profilingTime.getTime()} ms`)
logger.info(
`time for count transaction links in db: ${
new Date().getTime() - profilingTime.getTime()
} ms`,
)
profilingTime = new Date()
// The decay is always calculated on the last booked transaction
@ -96,7 +107,11 @@ export class BalanceResolver {
? { sumHoldAvailableAmount: context.sumHoldAvailableAmount }
: await transactionLinkSummary(user.id, now)
logger.info(`time for load transactionLinkSummary from db (if not already done): ${new Date().getTime() - profilingTime.getTime()} ms`)
logger.info(
`time for load transactionLinkSummary from db (if not already done): ${
new Date().getTime() - profilingTime.getTime()
} ms`,
)
profilingTime = new Date()
logger.debug(`context.sumHoldAvailableAmount=${context.sumHoldAvailableAmount}`)
@ -116,7 +131,14 @@ export class BalanceResolver {
count,
linkCount,
})
logger.info('new Balance', balance.toString(), balanceGDT?.toString(), count, linkCount, newBalance.toString())
logger.info(
'new Balance',
balance.toString(),
balanceGDT?.toString(),
count,
linkCount,
new BalanceLoggingView(newBalance),
)
return newBalance
}

View File

@ -309,7 +309,11 @@ export class TransactionResolver {
logger.debug(`involvedUserIds=`, involvedUserIds)
logger.debug(`involvedRemoteUsers=`, involvedRemoteUsers)
logger.info(`time for collect involved user and load remote user: ${new Date().getTime() - profilingTime.getTime()} ms`)
logger.info(
`time for collect involved user and load remote user: ${
new Date().getTime() - profilingTime.getTime()
} ms`,
)
profilingTime = new Date()
// We need to show the name for deleted users for old transactions
@ -320,7 +324,9 @@ export class TransactionResolver {
})
const involvedUsers = involvedDbUsers.map((u) => new User(u))
logger.debug(`involvedUsers=`, involvedUsers)
logger.info(`time for load involved user from db: ${new Date().getTime() - profilingTime.getTime()} ms`)
logger.info(
`time for load involved user from db: ${new Date().getTime() - profilingTime.getTime()} ms`,
)
profilingTime = new Date()
const self = new User(user)
@ -329,7 +335,11 @@ export class TransactionResolver {
const { sumHoldAvailableAmount, sumAmount, lastDate, firstDate, transactionLinkcount } =
await transactionLinkSummary(user.id, now)
logger.debug(`time for load transactionLinkSummary db: ${new Date().getTime() - profilingTime.getTime()} ms`)
logger.debug(
`time for load transactionLinkSummary db: ${
new Date().getTime() - profilingTime.getTime()
} ms`,
)
profilingTime = new Date()
context.linkCount = transactionLinkcount
@ -426,7 +436,11 @@ export class TransactionResolver {
).toDecimalPlaces(2, Decimal.ROUND_HALF_UP)
}
})
logger.info(`time for process transaction list and fill in decay db: ${new Date().getTime() - profilingTime.getTime()} ms`)
logger.info(
`time for process transaction list and fill in decay db: ${
new Date().getTime() - profilingTime.getTime()
} ms`,
)
profilingTime = new Date()
// Construct Result
return new TransactionList(await balanceResolver.balance(context), transactions)

View File

@ -0,0 +1,18 @@
import { Balance } from '@/graphql/model/Balance'
import { AbstractLoggingView } from '@logging/AbstractLogging.view'
export class BalanceLoggingView extends AbstractLoggingView {
public constructor(private self: Balance) {
super()
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public toJSON(): any {
return {
balance: this.decimalToString(this.self.balance),
balanceGDT: this.self.balanceGDT,
count: this.self.count,
linkCount: this.self.linkCount,
}
}
}

View File

@ -1,6 +1,7 @@
import { Decay } from '@/graphql/model/Decay'
import { AbstractLoggingView } from '@logging/AbstractLogging.view'
import { Decay } from '@/graphql/model/Decay'
export class DecayLoggingView extends AbstractLoggingView {
public constructor(private self: Decay) {
super()
@ -14,7 +15,7 @@ export class DecayLoggingView extends AbstractLoggingView {
roundedDecay: this.decimalToString(this.self.roundedDecay),
start: this.dateToString(this.self.start),
end: this.dateToString(this.self.end),
duration: this.self.duration
duration: this.self.duration,
}
}
}