@@ -15,51 +15,49 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
1515 }
1616
1717 async insert ( data : CoaMysql . SafePartial < Scheme > , trx ?: CoaMysql . Transaction ) {
18- const id = await super . insert ( data , trx )
18+ const id = await super . insert ( data , trx ) ;
1919 trx && ( trx as any ) . trxUpdateCacheTaskList ? await ( trx as any ) . trxUpdateCacheTaskList ( this , [ id ] , [ data ] ) : await this . deleteCache ( [ id ] , [ data ] )
2020 return id
2121 }
2222
2323 async mInsert ( dataList : Array < CoaMysql . SafePartial < Scheme > > , trx ?: CoaMysql . Transaction ) {
24- const ids = await super . mInsert ( dataList , trx )
24+ const ids = await super . mInsert ( dataList , trx ) ;
2525 trx && ( trx as any ) . trxUpdateCacheTaskList ? await ( trx as any ) . trxUpdateCacheTaskList ( this , ids , dataList ) : await this . deleteCache ( ids , dataList )
2626 return ids
2727 }
2828
2929 async updateById ( id : string , data : CoaMysql . SafePartial < Scheme > , trx ?: CoaMysql . Transaction ) {
3030 const dataList = await this . getCacheChangedDataList ( [ id ] , data , trx )
31- const result = await super . updateById ( id , data , trx )
31+ const result = await super . updateById ( id , data , trx ) ;
3232 trx && ( trx as any ) . trxUpdateCacheTaskList ? await ( trx as any ) . trxUpdateCacheTaskList ( this , [ id ] , dataList ) : await this . deleteCache ( [ id ] , dataList )
3333 return result
3434 }
3535
3636 async updateByIds ( ids : string [ ] , data : CoaMysql . SafePartial < Scheme > , trx ?: CoaMysql . Transaction ) {
3737 const dataList = await this . getCacheChangedDataList ( ids , data , trx )
38- const result = await super . updateByIds ( ids , data , trx )
38+ const result = await super . updateByIds ( ids , data , trx ) ;
3939 trx && ( trx as any ) . trxUpdateCacheTaskList ? await ( trx as any ) . trxUpdateCacheTaskList ( this , ids , dataList ) : await this . deleteCache ( ids , dataList )
4040 return result
4141 }
4242
4343 async updateForQueryById ( id : string , query : CoaMysql . Query , data : CoaMysql . SafePartial < Scheme > , trx ?: CoaMysql . Transaction ) {
4444 const dataList = await this . getCacheChangedDataList ( [ id ] , data , trx )
45- const result = await super . updateForQueryById ( id , query , data , trx )
45+ const result = await super . updateForQueryById ( id , query , data , trx ) ;
4646 trx && ( trx as any ) . trxUpdateCacheTaskList ? await ( trx as any ) . trxUpdateCacheTaskList ( this , [ id ] , dataList ) : await this . deleteCache ( [ id ] , dataList )
4747 return result
4848 }
4949
5050 async upsertById ( id : string , data : CoaMysql . SafePartial < Scheme > , trx ?: CoaMysql . Transaction ) {
5151 const dataList = await this . getCacheChangedDataList ( [ id ] , data , trx )
52- const result = await super . upsertById ( id , data , trx )
52+ const result = await super . upsertById ( id , data , trx ) ;
5353 trx && ( trx as any ) . trxUpdateCacheTaskList ? await ( trx as any ) . trxUpdateCacheTaskList ( this , [ id ] , dataList ) : await this . deleteCache ( [ id ] , dataList )
5454 return result
5555 }
5656
5757 async deleteByIds ( ids : string [ ] , trx ?: CoaMysql . Transaction ) {
5858 const dataList = await this . getCacheChangedDataList ( ids , undefined , trx )
59- const result = await super . deleteByIds ( ids , trx )
60- if ( result ) {
61- ( trx && ( trx as any ) . trxUpdateCacheTaskList ) ? await ( trx as any ) . trxUpdateCacheTaskList ( this , ids , dataList ) : await this . deleteCache ( ids , dataList )
62- }
59+ const result = await super . deleteByIds ( ids , trx ) ;
60+ trx && ( trx as any ) . trxUpdateCacheTaskList ? await ( trx as any ) . trxUpdateCacheTaskList ( this , ids , dataList ) : await this . deleteCache ( ids , dataList )
6361 return result
6462 }
6563
@@ -117,12 +115,8 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
117115 _ . forEach ( rows , ( { id, count } ) => ( result [ id ] = count ) )
118116 return result
119117 }
120-
121- if ( trx ) {
122- return await queryFunction ( )
123- } else {
124- return await this . redisCache . mWarp ( this . getCacheNsp ( 'count' , field ) , ids , queryFunction )
125- }
118+ const result = trx ? await queryFunction ( ) : await this . redisCache . mWarp ( this . getCacheNsp ( 'count' , field ) , ids , queryFunction )
119+ return result
126120 }
127121
128122 protected async getCountBy ( field : string , value : string , query ?: CoaMysql . Query , trx ?: CoaMysql . Transaction ) {
@@ -132,14 +126,8 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
132126 const rows = await qb
133127 return ( rows [ 0 ] ?. count as number ) || 0
134128 }
135-
136- if ( trx ) {
137- // 事务内直接查询数据库,不走缓存
138- return await queryFunction ( )
139- } else {
140- // 非事务走缓存
141- return await this . redisCache . warp ( this . getCacheNsp ( 'count' , field ) , value , queryFunction )
142- }
129+ const result = trx ? await queryFunction ( ) : await this . redisCache . warp ( this . getCacheNsp ( 'count' , field ) , value , queryFunction )
130+ return result
143131 }
144132
145133 protected pickResult < T > ( data : T , pick : string [ ] ) {
0 commit comments