@@ -20,7 +20,7 @@ export class WalletAddress extends BaseModel<IWalletAddress> {
2020 allowedPaging = [ ] ;
2121
2222 onConnect ( ) {
23- this . collection . createIndex ( { address : 1 , wallet : 1 } ) ;
23+ this . collection . createIndex ( { address : 1 , wallet : 1 } , { background : true } ) ;
2424 }
2525
2626 _apiTransform ( walletAddress : { address : string } , options : TransformOptions ) {
@@ -65,20 +65,33 @@ export class WalletAddress extends BaseModel<IWalletAddress> {
6565 return new Promise ( async resolve => {
6666 for ( const address of addresses ) {
6767 await Promise . all ( [
68- WalletAddressModel . collection . updateOne ( { wallet : wallet . _id , address } , { $set : { wallet : wallet . _id , address : address , chain, network } } , { upsert : true } ) ,
69- CoinModel . collection . updateMany ( { chain, network, address } , { $addToSet : { wallets : wallet . _id } } )
68+ WalletAddressModel . collection . updateOne (
69+ { wallet : wallet . _id , address } ,
70+ { $set : { wallet : wallet . _id , address : address , chain, network } } ,
71+ { upsert : true }
72+ ) ,
73+ CoinModel . collection . updateMany ( { chain, network, address } , { $addToSet : { wallets : wallet . _id } } )
7074 ] ) ;
7175 }
7276
73- let coinStream = CoinModel . collection . find ( { wallets : wallet . _id } ) . project ( { spentTxid : 1 , mintTxid : 1 } ) . addCursorFlag ( 'noCursorTimeout' , true ) ;
77+ let coinStream = CoinModel . collection
78+ . find ( { wallets : wallet . _id } )
79+ . project ( { spentTxid : 1 , mintTxid : 1 } )
80+ . addCursorFlag ( 'noCursorTimeout' , true ) ;
7481 let txids = { } ;
7582 coinStream . on ( 'data' , ( coin : ICoin ) => {
7683 if ( ! txids [ coin . mintTxid ] ) {
77- TransactionModel . collection . update ( { txid : coin . mintTxid , network, chain } , { $addToSet : { wallets : wallet . _id } } ) ;
84+ TransactionModel . collection . update (
85+ { txid : coin . mintTxid , network, chain } ,
86+ { $addToSet : { wallets : wallet . _id } }
87+ ) ;
7888 }
7989 txids [ coin . mintTxid ] = true ;
8090 if ( ! txids [ coin . spentTxid ] ) {
81- TransactionModel . collection . update ( { txid : coin . spentTxid , network, chain } , { $addToSet : { wallets : wallet . _id } } ) ;
91+ TransactionModel . collection . update (
92+ { txid : coin . spentTxid , network, chain } ,
93+ { $addToSet : { wallets : wallet . _id } }
94+ ) ;
8295 }
8396 txids [ coin . spentTxid ] = true ;
8497 } ) ;
0 commit comments