File tree Expand file tree Collapse file tree 1 file changed +28
-7
lines changed Expand file tree Collapse file tree 1 file changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -198,23 +198,44 @@ impl MerchantAccountInterface for Store {
198
198
& self ,
199
199
publishable_key : & str ,
200
200
) -> CustomResult < authentication:: AuthenticationData , errors:: StorageError > {
201
- let conn = connection:: pg_connection_read ( self ) . await ?;
202
- let merchant = storage:: MerchantAccount :: find_by_publishable_key ( & conn, publishable_key)
203
- . await
204
- . map_err ( Into :: into)
205
- . into_report ( ) ?;
201
+ let fetch_by_pub_key_func = || async {
202
+ let conn = connection:: pg_connection_read ( self ) . await ?;
203
+
204
+ storage:: MerchantAccount :: find_by_publishable_key ( & conn, publishable_key)
205
+ . await
206
+ . map_err ( Into :: into)
207
+ . into_report ( )
208
+ } ;
209
+
210
+ let merchant_account;
211
+ #[ cfg( not( feature = "accounts_cache" ) ) ]
212
+ {
213
+ merchant_account = fetch_by_pub_key_func ( ) . await ?;
214
+ }
215
+
216
+ #[ cfg( feature = "accounts_cache" ) ]
217
+ {
218
+ merchant_account = super :: cache:: get_or_populate_in_memory (
219
+ self ,
220
+ publishable_key,
221
+ fetch_by_pub_key_func,
222
+ & ACCOUNTS_CACHE ,
223
+ )
224
+ . await ?;
225
+ }
206
226
let key_store = self
207
227
. get_merchant_key_store_by_merchant_id (
208
- & merchant . merchant_id ,
228
+ & merchant_account . merchant_id ,
209
229
& self . get_master_key ( ) . to_vec ( ) . into ( ) ,
210
230
)
211
231
. await ?;
212
232
213
233
Ok ( authentication:: AuthenticationData {
214
- merchant_account : merchant
234
+ merchant_account : merchant_account
215
235
. convert ( key_store. key . get_inner ( ) )
216
236
. await
217
237
. change_context ( errors:: StorageError :: DecryptionError ) ?,
238
+
218
239
key_store,
219
240
} )
220
241
}
You can’t perform that action at this time.
0 commit comments