@@ -82,7 +82,8 @@ public MediaPicker3PropertyValueEditor(
8282 IDataTypeConfigurationCache dataTypeReadCache ,
8383 ILocalizedTextService localizedTextService ,
8484 IMediaTypeService mediaTypeService ,
85- IMediaNavigationQueryService mediaNavigationQueryService )
85+ IMediaNavigationQueryService mediaNavigationQueryService ,
86+ AppCaches appCaches )
8687 : base ( shortStringHelper , jsonSerializer , ioHelper , attribute )
8788 {
8889 _jsonSerializer = jsonSerializer ;
@@ -95,7 +96,7 @@ public MediaPicker3PropertyValueEditor(
9596 var validators = new TypedJsonValidatorRunner < List < MediaWithCropsDto > , MediaPicker3Configuration > (
9697 jsonSerializer ,
9798 new MinMaxValidator ( localizedTextService ) ,
98- new AllowedTypeValidator ( localizedTextService , mediaTypeService , _mediaService ) ,
99+ new AllowedTypeValidator ( localizedTextService , mediaTypeService , _mediaService , appCaches ) ,
99100 new StartNodeValidator ( localizedTextService , mediaNavigationQueryService ) ) ;
100101
101102 Validators . Add ( validators ) ;
@@ -401,18 +402,22 @@ public IEnumerable<ValidationResult> Validate(
401402 /// </summary>
402403 internal sealed class AllowedTypeValidator : ITypedJsonValidator < List < MediaWithCropsDto > , MediaPicker3Configuration >
403404 {
405+ private const string MediaTypeCacheKeyFormat = nameof ( AllowedTypeValidator ) + "_MediaTypeKey_{0}" ;
406+
404407 private readonly ILocalizedTextService _localizedTextService ;
405408 private readonly IMediaTypeService _mediaTypeService ;
406409 private readonly IMediaService _mediaService ;
410+ private readonly AppCaches _appCaches ;
407411
408412 /// <summary>
409413 /// Initializes a new instance of the <see cref="AllowedTypeValidator"/> class.
410414 /// </summary>
411- public AllowedTypeValidator ( ILocalizedTextService localizedTextService , IMediaTypeService mediaTypeService , IMediaService mediaService )
415+ public AllowedTypeValidator ( ILocalizedTextService localizedTextService , IMediaTypeService mediaTypeService , IMediaService mediaService , AppCaches appCaches )
412416 {
413417 _localizedTextService = localizedTextService ;
414418 _mediaTypeService = mediaTypeService ;
415419 _mediaService = mediaService ;
420+ _appCaches = appCaches ;
416421 }
417422
418423 /// <inheritdoc/>
@@ -452,9 +457,20 @@ public IEnumerable<ValidationResult> Validate(
452457
453458 foreach ( var typeAlias in distinctTypeAliases )
454459 {
455- IMediaType ? type = _mediaTypeService . Get ( typeAlias ) ;
460+ // Cache media type lookups since the same media type is likely to be used multiple times in validation,
461+ // particularly if we have multiple languages and blocks.
462+ var cacheKey = string . Format ( MediaTypeCacheKeyFormat , typeAlias ) ;
463+ string ? typeKey = _appCaches . RequestCache . GetCacheItem < string ? > ( cacheKey ) ;
464+ if ( typeKey is null )
465+ {
466+ typeKey = _mediaTypeService . Get ( typeAlias ) ? . Key . ToString ( ) ;
467+ if ( typeKey is not null )
468+ {
469+ _appCaches . RequestCache . Set ( cacheKey , typeKey ) ;
470+ }
471+ }
456472
457- if ( type is null || allowedTypes . Contains ( type . Key . ToString ( ) ) is false )
473+ if ( typeKey is null || allowedTypes . Contains ( typeKey ) is false )
458474 {
459475 return
460476 [
0 commit comments