@@ -62,6 +62,12 @@ export class LogJobService {
6262
6363 private readonly unavailableClientWarningsLogged = new Set < Blockchain > ( ) ;
6464
65+ private paymentBalanceCache : Map < number , BlockchainTokenBalance > = new Map ( ) ;
66+ private paymentBalanceCacheTime : Date = new Date ( 0 ) ;
67+
68+ private customBalanceCache : { blockchain : Blockchain ; balances : BlockchainTokenBalance [ ] } [ ] = [ ] ;
69+ private customBalanceCacheTime : Date = new Date ( 0 ) ;
70+
6571 constructor (
6672 private readonly tradingRuleService : TradingRuleService ,
6773 private readonly assetService : AssetService ,
@@ -216,32 +222,40 @@ export class LogJobService {
216222 } ) ,
217223 ) ;
218224
219- const customBalances = await Promise . all (
220- Array . from ( customAssetMap . entries ( ) ) . map ( async ( [ b , a ] ) => {
221- try {
222- const client = this . blockchainRegistryService . getClient ( b ) ;
223- if ( ! client ) {
224- if ( ! this . unavailableClientWarningsLogged . has ( b ) ) {
225- this . logger . warn ( `Blockchain client not configured for ${ b } - skipping custom balances` ) ;
226- this . unavailableClientWarningsLogged . add ( b ) ;
225+ if ( Util . minutesDiff ( this . customBalanceCacheTime ) >= 60 ) {
226+ this . customBalanceCache = await Promise . all (
227+ Array . from ( customAssetMap . entries ( ) ) . map ( async ( [ b , a ] ) => {
228+ try {
229+ const client = this . blockchainRegistryService . getClient ( b ) ;
230+ if ( ! client ) {
231+ if ( ! this . unavailableClientWarningsLogged . has ( b ) ) {
232+ this . logger . warn ( `Blockchain client not configured for ${ b } - skipping custom balances` ) ;
233+ this . unavailableClientWarningsLogged . add ( b ) ;
234+ }
235+ return { blockchain : b , balances : [ ] } ;
227236 }
237+
238+ const balances = await Util . timeout (
239+ this . getCustomBalances ( client , a , Config . financialLog . customAddresses ) . then ( ( b ) => b . flat ( ) ) ,
240+ 30000 ,
241+ ) ;
242+ return { blockchain : b , balances } ;
243+ } catch ( e ) {
244+ this . logger . error ( `Error in FinanceLog customBalances for blockchain ${ b } :` , e ) ;
228245 return { blockchain : b , balances : [ ] } ;
229246 }
230-
231- const balances = await Util . timeout (
232- this . getCustomBalances ( client , a , Config . financialLog . customAddresses ) . then ( ( b ) => b . flat ( ) ) ,
233- 30000 ,
234- ) ;
235- return { blockchain : b , balances } ;
236- } catch ( e ) {
237- this . logger . error ( `Error in FinanceLog customBalances for blockchain ${ b } :` , e ) ;
238- return { blockchain : b , balances : [ ] } ;
239- }
240- } ) ,
241- ) ;
247+ } ) ,
248+ ) ;
249+ this . customBalanceCacheTime = new Date ( ) ;
250+ }
251+ const customBalances = this . customBalanceCache ;
242252
243253 // payment deposit address balance (Monero/Lightning have no separated balance)
244- const paymentDepositBalances = await this . paymentBalanceService . getPaymentBalances ( assets , true ) ;
254+ if ( Util . minutesDiff ( this . paymentBalanceCacheTime ) >= 60 ) {
255+ this . paymentBalanceCache = await this . paymentBalanceService . getPaymentBalances ( assets , true ) ;
256+ this . paymentBalanceCacheTime = new Date ( ) ;
257+ }
258+ const paymentDepositBalances = this . paymentBalanceCache ;
245259
246260 // banks
247261 const olkyBank = await this . bankService . getBankInternal ( IbanBankName . OLKY , 'EUR' ) ;
0 commit comments