@@ -70,11 +70,11 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
7070 }
7171
7272 async getIdBy ( field : string , value : string | number , trx ?: CoaMysql . Transaction ) {
73- return ( trx as any ) . __isSafeTransaction ? await super . getIdBy ( field , value , trx ) : await this . redisCache . warp ( this . getCacheNsp ( 'index' , field ) , '' + value , async ( ) => await super . getIdBy ( field , value , trx ) )
73+ return trx ? .__isSafeTransaction ? await super . getIdBy ( field , value , trx ) : await this . redisCache . warp ( this . getCacheNsp ( 'index' , field ) , '' + value , async ( ) => await super . getIdBy ( field , value , trx ) )
7474 }
7575
7676 async mGetByIds ( ids : string [ ] , pick = this . pick , trx ?: CoaMysql . Transaction , ms = this . ms , force = false ) {
77- const result = ( trx as any ) . __isSafeTransaction ? await super . mGetByIds ( ids , this . columns , trx ) : await this . redisCache . mWarp ( this . getCacheNsp ( 'id' ) , ids , async ids => await super . mGetByIds ( ids , this . columns , trx ) , ms , force )
77+ const result = trx ? .__isSafeTransaction ? await super . mGetByIds ( ids , this . columns , trx ) : await this . redisCache . mWarp ( this . getCacheNsp ( 'id' ) , ids , async ids => await super . mGetByIds ( ids , this . columns , trx ) , ms , force )
7878 _ . forEach ( result , ( v , k ) => {
7979 result [ k ] = this . pickResult ( v , pick )
8080 } )
@@ -88,23 +88,23 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
8888
8989 protected async findListCount ( finger : Array < CoaMysql . Dic < any > > , query : CoaMysql . Query , trx ?: CoaMysql . Transaction ) {
9090 const cacheId = 'list-count:' + secure . sha1 ( $ . sortQueryString ( ...finger ) )
91- return ( trx as any ) ?. __isSafeTransaction ? await super . selectListCount ( query , trx ) : await this . redisCache . warp ( this . getCacheNsp ( 'data' ) , cacheId , async ( ) => await super . selectListCount ( query , trx ) )
91+ return trx ?. __isSafeTransaction ? await super . selectListCount ( query , trx ) : await this . redisCache . warp ( this . getCacheNsp ( 'data' ) , cacheId , async ( ) => await super . selectListCount ( query , trx ) )
9292 }
9393
9494 protected async findIdList ( finger : Array < CoaMysql . Dic < any > > , query : CoaMysql . Query , trx ?: CoaMysql . Transaction ) {
9595 const cacheId = 'list:' + secure . sha1 ( $ . sortQueryString ( ...finger ) )
96- return ( trx as any ) ?. __isSafeTransaction ? await super . selectIdList ( query , trx ) : await this . redisCache . warp ( this . getCacheNsp ( 'data' ) , cacheId , async ( ) => await super . selectIdList ( query , trx ) )
96+ return trx ?. __isSafeTransaction ? await super . selectIdList ( query , trx ) : await this . redisCache . warp ( this . getCacheNsp ( 'data' ) , cacheId , async ( ) => await super . selectIdList ( query , trx ) )
9797 }
9898
9999 protected async findIdSortList ( finger : Array < CoaMysql . Dic < any > > , pager : CoaMysql . Pager , query : CoaMysql . Query , trx ?: CoaMysql . Transaction ) {
100100 const cacheId = `sort-list:${ pager . rows } :${ pager . last } :` + secure . sha1 ( $ . sortQueryString ( ...finger ) )
101- return ( trx as any ) ?. __isSafeTransaction ? await super . selectIdSortList ( pager , query , trx ) : await this . redisCache . warp ( this . getCacheNsp ( 'data' ) , cacheId , async ( ) => await super . selectIdSortList ( pager , query , trx ) )
101+ return trx ?. __isSafeTransaction ? await super . selectIdSortList ( pager , query , trx ) : await this . redisCache . warp ( this . getCacheNsp ( 'data' ) , cacheId , async ( ) => await super . selectIdSortList ( pager , query , trx ) )
102102 }
103103
104104 protected async findIdViewList ( finger : Array < CoaMysql . Dic < any > > , pager : CoaMysql . Pager , query : CoaMysql . Query , trx ?: CoaMysql . Transaction ) {
105105 const cacheId = `view-list:${ pager . rows } :${ pager . page } :` + secure . sha1 ( $ . sortQueryString ( ...finger ) )
106106 const count = await this . findListCount ( finger , query , trx )
107- return ( trx as any ) ?. __isSafeTransaction ? await super . selectIdViewList ( pager , query , trx , count ) : await this . redisCache . warp ( this . getCacheNsp ( 'data' ) , cacheId , async ( ) => await super . selectIdViewList ( pager , query , trx , count ) )
107+ return trx ?. __isSafeTransaction ? await super . selectIdViewList ( pager , query , trx , count ) : await this . redisCache . warp ( this . getCacheNsp ( 'data' ) , cacheId , async ( ) => await super . selectIdViewList ( pager , query , trx , count ) )
108108 }
109109
110110 protected async mGetCountBy ( field : string , ids : string [ ] , trx ?: CoaMysql . Transaction ) {
@@ -114,7 +114,7 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
114114 _ . forEach ( rows , ( { id, count } ) => ( result [ id ] = count ) )
115115 return result
116116 }
117- const result = ( trx as any ) ?. __isSafeTransaction ? await queryFunction ( ) : await this . redisCache . mWarp ( this . getCacheNsp ( 'count' , field ) , ids , queryFunction )
117+ const result = trx ?. __isSafeTransaction ? await queryFunction ( ) : await this . redisCache . mWarp ( this . getCacheNsp ( 'count' , field ) , ids , queryFunction )
118118 return result
119119 }
120120
@@ -125,7 +125,7 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
125125 const rows = await qb
126126 return ( rows [ 0 ] ?. count as number ) || 0
127127 }
128- const result = ( trx as any ) ?. __isSafeTransaction ? await queryFunction ( ) : await this . redisCache . warp ( this . getCacheNsp ( 'count' , field ) , value , queryFunction )
128+ const result = trx ?. __isSafeTransaction ? await queryFunction ( ) : await this . redisCache . warp ( this . getCacheNsp ( 'count' , field ) , value , queryFunction )
129129 return result
130130 }
131131
@@ -154,7 +154,7 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
154154
155155 async deleteCache ( ids : string [ ] , dataList : Array < CoaMysql . SafePartial < Scheme > > , trx ?: CoaMysql . Transaction ) {
156156 const deleteIds = [ ] as CoaRedis . CacheDelete [ ]
157- if ( ( trx as any ) ?. __isSafeTransaction ) {
157+ if ( trx ?. __isSafeTransaction ) {
158158 ( trx as any ) ?. clearCacheNsps . push ( [ this . getCacheNsp ( 'id' ) , ids ] ) ;
159159 ( trx as any ) ?. clearCacheNsps . push ( [ this . getCacheNsp ( 'data' ) , [ ] ] )
160160 } else {
@@ -172,10 +172,10 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
172172 } )
173173 ids . push ( ...keys . slice ( 1 ) )
174174 if ( ids . length ) {
175- ( ( trx as any ) ?. __isSafeTransaction ) ? ( trx as any ) ?. clearCacheNsps . push ( [ this . getCacheNsp ( name , key ) , ids ] ) : deleteIds . push ( [ this . getCacheNsp ( name , key ) , ids ] )
175+ ( trx ?. __isSafeTransaction ) ? ( trx as any ) ?. clearCacheNsps . push ( [ this . getCacheNsp ( name , key ) , ids ] ) : deleteIds . push ( [ this . getCacheNsp ( name , key ) , ids ] )
176176 }
177177 } )
178178 } )
179- if ( ! ( trx as any ) ?. __isSafeTransaction ) await this . redisCache . mDelete ( deleteIds )
179+ if ( ! trx ?. __isSafeTransaction ) await this . redisCache . mDelete ( deleteIds )
180180 }
181181}
0 commit comments