@@ -74,7 +74,7 @@ export class ACSHelper {
7474 cacheSize : this . contractsSet . size ,
7575 hitRate : hitRate . toFixed ( 2 ) + '%' ,
7676 averageLookupTime : avgLookupTime . toFixed ( 3 ) + ' ms' ,
77- cacheServeTime : this . totalCacheServeTime . toFixed ( 3 ) ,
77+ cacheServeTime : SharedACSCacheStats . totalCacheServeTime . toFixed ( 3 ) ,
7878 }
7979 }
8080
@@ -92,7 +92,7 @@ export class ACSHelper {
9292
9393 private findACSContainer ( key : ACSKey ) : ACSContainer {
9494 const keyStr = ACSHelper . keyToString ( key , this . apiInstance . baseUrl . href )
95- // this.logger.info(`ACS KEY ${keyStr}`)
95+
9696 const start = performance . now ( )
9797 const existing = this . contractsSet . get ( keyStr )
9898 const end = performance . now ( )
@@ -114,59 +114,84 @@ export class ACSHelper {
114114 return newContainer
115115 }
116116
117- async activeContractsForTemplate (
118- offset : number ,
119- partyFilter : string ,
120- templateId : string
121- ) : Promise < Array < JsGetActiveContractsResponse > > {
122- const key = ACSHelper . createKey ( partyFilter , templateId , undefined )
117+ async updateSingleKey ( offset : number , key : ACSKey ) {
123118 const start = performance . now ( )
124119 const container = this . findACSContainer ( key )
125- const result = container . update (
120+ const result = await container . update (
126121 offset ,
127122 key ,
128123 this . apiInstance ,
129124 this . wsSupport
130125 )
126+
131127 const end = performance . now ( )
132128
133- if (
134- this . contractsSet . has (
135- ACSHelper . keyToString ( key , this . apiInstance . baseUrl . href )
136- )
137- ) {
129+ const keyStr = ACSHelper . keyToString ( key , this . apiInstance . baseUrl . href )
130+
131+ if ( this . contractsSet . has ( keyStr ) ) {
138132 SharedACSCacheStats . totalCacheServeTime += end - start
139133 }
140134
141135 return result
142136 }
143137
144- async activeContractsForInterface (
138+ async queryAcsByKeys ( offset : number , keys : ACSKey [ ] ) {
139+ const result : JsGetActiveContractsResponse [ ] = [ ]
140+
141+ for ( const key of keys ) {
142+ const contracts = await this . updateSingleKey ( offset , key )
143+ result . push ( ...contracts )
144+ }
145+
146+ return result
147+ }
148+
149+ async activeContractsForTemplates (
145150 offset : number ,
146- partyFilter : string | undefined ,
147- interfaceId : string
148- ) : Promise < Array < JsGetActiveContractsResponse > > {
149- const key = ACSHelper . createKey ( partyFilter , undefined , interfaceId )
150- const start = performance . now ( )
151- const container = this . findACSContainer ( key )
151+ parties : PartyId [ ] ,
152+ templateIds : string [ ]
153+ ) : Promise < JsGetActiveContractsResponse [ ] > {
154+ const keys = parties . flatMap ( ( party ) =>
155+ templateIds . map ( ( templateId ) =>
156+ ACSHelper . createKey ( party , templateId , undefined )
157+ )
158+ )
159+ return this . queryAcsByKeys ( offset , keys )
160+ }
152161
153- const result = container . update (
154- offset ,
155- key ,
156- this . apiInstance ,
157- this . wsSupport
162+ async activeContractsForInterfaces (
163+ offset : number ,
164+ parties : PartyId [ ] ,
165+ interfaceIds : string [ ]
166+ ) : Promise < JsGetActiveContractsResponse [ ] > {
167+ const keys = parties . flatMap ( ( party ) =>
168+ interfaceIds . map ( ( interfaceId ) =>
169+ ACSHelper . createKey ( party , undefined , interfaceId )
170+ )
158171 )
159172
160- const end = performance . now ( )
173+ return this . queryAcsByKeys ( offset , keys )
174+ }
161175
162- if (
163- this . contractsSet . has (
164- ACSHelper . keyToString ( key , this . apiInstance . baseUrl . href )
165- )
166- ) {
167- SharedACSCacheStats . totalCacheServeTime += end - start
168- }
176+ async activeContractsForTemplate (
177+ offset : number ,
178+ partyFilter : PartyId ,
179+ templateId : string
180+ ) : Promise < JsGetActiveContractsResponse [ ] > {
181+ return this . updateSingleKey (
182+ offset ,
183+ ACSHelper . createKey ( partyFilter , templateId , undefined )
184+ )
185+ }
169186
170- return result
187+ async activeContractsForInterface (
188+ offset : number ,
189+ partyFilter : PartyId | undefined ,
190+ interfaceId : string
191+ ) : Promise < Array < JsGetActiveContractsResponse > > {
192+ return this . updateSingleKey (
193+ offset ,
194+ ACSHelper . createKey ( partyFilter , undefined , interfaceId )
195+ )
171196 }
172197}
0 commit comments