1
1
/* eslint-disable arrow-parens */
2
2
import config from 'config' ;
3
3
import models from 'db/models' ;
4
- import { updateRecordCache2 } from 'db/cache' ;
4
+ import { clearPendingRewardCache } from 'db/cache' ;
5
5
import { Model } from 'sequelize' ;
6
6
import { log } from 'server/utils/loggers' ;
7
7
@@ -16,59 +16,24 @@ const clearPendingClaimTronReward = function*(username) {
16
16
} ) ;
17
17
t2 = process . uptime ( ) * 1000 ;
18
18
log ( '[timer] clearPendingClaimTronReward findOne' , { t : t2 - t1 } ) ;
19
- if ( user && user . getDataValue ( 'pending_claim_tron_reward' ) > 0 ) {
20
- const pendingClaimTronReward =
21
- user . getDataValue ( 'pending_claim_tron_reward' ) / 1e6 ;
22
- // transaction
19
+ if ( user ) {
23
20
t1 = process . uptime ( ) * 1000 ;
24
- yield models . sequelize . transaction ( ) . then ( transaction => {
25
- // clear pending_claim_tron_reward
26
- return user
27
- . update (
28
- {
29
- pending_claim_tron_reward : 0 ,
30
- } ,
31
- {
32
- transaction,
33
- }
34
- )
35
- . then ( ( ) =>
36
- models . TronReward . create (
37
- {
38
- username,
39
- tron_addr : user . get ( 'tron_addr' ) ,
40
- block_num : 0 ,
41
- steem_tx_id : '' ,
42
- reward_vests : `${ pendingClaimTronReward *
43
- vestsPerTrx } VESTS`,
44
- reward_steem : '0 STEEM' ,
45
- reward_sbd : '0 SBD' ,
46
- vests_per_steem : 0 ,
47
- reward_type : 1 ,
48
- } ,
49
- {
50
- transaction,
51
- }
52
- )
53
- )
54
- . then ( ( ) => transaction . commit ( ) )
55
- . catch ( err => {
56
- transaction . rollback ( ) ;
57
- log ( 'clear_pending_claim_tron_reward_error:' , {
58
- msg : err . message ,
59
- } ) ;
60
- } ) ;
61
- } ) ;
21
+ yield models . TronReward . update (
22
+ {
23
+ tron_addr : user . tron_addr ,
24
+ } ,
25
+ {
26
+ where : {
27
+ username,
28
+ tron_addr : null ,
29
+ reward_type : 0 ,
30
+ } ,
31
+ }
32
+ ) ;
62
33
t2 = process . uptime ( ) * 1000 ;
34
+ // clear redis cache
35
+ yield clearPendingRewardCache ( models . TronReward , username ) ;
63
36
log ( '[timer] clearPendingClaimTronReward transaction:' , { t : t2 - t1 } ) ;
64
- t1 = process . uptime ( ) * 1000 ;
65
- yield updateRecordCache2 (
66
- models . TronUser ,
67
- models . escAttrs ( { username } )
68
- ) ;
69
- log ( '[timer] clearPendingClaimTronReward updateRecordCache2:' , {
70
- t : process . uptime ( ) * 1000 - t1 ,
71
- } ) ;
72
37
}
73
38
} ;
74
39
0 commit comments