@@ -149,12 +149,21 @@ export function getConfig(params: GetConfigParams): RawConfig {
149
149
150
150
const accounts = params . accounts ;
151
151
152
+ // Create a map of parsed base data for each account to avoid repeated parsing
153
+ const parsedBaseDataMap = new Map (
154
+ accounts . map ( ( account ) => {
155
+ const baseData = parseBaseData ( account . account . data ) ;
156
+ return [ account . pubkey . toBase58 ( ) , baseData ] ;
157
+ } ) ,
158
+ ) ;
159
+
152
160
// First pass: Extract price accounts
153
161
const priceRawConfigs = Object . fromEntries (
154
162
accounts
155
163
. filter (
156
164
( account ) =>
157
- parseBaseData ( account . account . data ) ?. type === AccountType . Price ,
165
+ parsedBaseDataMap . get ( account . pubkey . toBase58 ( ) ) ?. type ===
166
+ AccountType . Price ,
158
167
)
159
168
. map ( ( account ) => {
160
169
const parsed = parsePriceData ( account . account . data ) ;
@@ -179,7 +188,8 @@ export function getConfig(params: GetConfigParams): RawConfig {
179
188
accounts
180
189
. filter (
181
190
( account ) =>
182
- parseBaseData ( account . account . data ) ?. type === AccountType . Product ,
191
+ parsedBaseDataMap . get ( account . pubkey . toBase58 ( ) ) ?. type ===
192
+ AccountType . Product ,
183
193
)
184
194
. map ( ( account ) => {
185
195
const parsed = parseProductData ( account . account . data ) ;
@@ -225,7 +235,8 @@ export function getConfig(params: GetConfigParams): RawConfig {
225
235
const mappingAccounts = accounts
226
236
. filter (
227
237
( account ) =>
228
- parseBaseData ( account . account . data ) ?. type === AccountType . Mapping ,
238
+ parsedBaseDataMap . get ( account . pubkey . toBase58 ( ) ) ?. type ===
239
+ AccountType . Mapping ,
229
240
)
230
241
. map ( ( account ) => {
231
242
const parsed = parseMappingData ( account . account . data ) ;
@@ -253,7 +264,8 @@ export function getConfig(params: GetConfigParams): RawConfig {
253
264
// Find permission account if it exists
254
265
const permissionAccount = accounts . find (
255
266
( account ) =>
256
- parseBaseData ( account . account . data ) ?. type === AccountType . Permission ,
267
+ parsedBaseDataMap . get ( account . pubkey . toBase58 ( ) ) ?. type ===
268
+ AccountType . Permission ,
257
269
) ;
258
270
259
271
if ( permissionAccount ) {
0 commit comments