Try our conversational search powered by Generative AI!

Getting asset BlobUid when uzing Amazon S3 provider

Vote:
 

We have product list page that shows lats say ~ 100 products.

For each product we have multiple assets, like: 3 logos, main picture, 3 labels, etc..

I dont know if that realy changes anything(because all the data I need is still in local commerce db tables), but we are using amazon s3 provider.

So to get all those 100 products(or SKU's) we just need to use one API call and we are getting collection of Entry records and each of them has Assets, only thing is Assets have their own internal ids witch cannot be used to generate links agains amazon s3, so that is why we used:

var asset = assets.ElementAt(index);
var folderElements = 
  EntityManager.List<FolderElementEntity>(FolderElementEntity.ClassName,
                                          FilterElement.EqualElement(FolderElementEntity.PrimaryKeyName, asset.AssetKey));

var amazonUniqueIdentifierWeNeed = folderElements[0].BlobUid;

as described in SDK: http://sdk.episerver.com/commerce/1.1.2/Content/Developers%20Guide/Tutorials/Training/TrainAssetAPI.htm

but the problem is as we have about 100 products per page and each product has lets say 7 assets we need to call 'EntityManager.List' about 700 times, and that is not fast, and i probably know why cos when I used reflector to look inside it i saw that it needs to execute almost gazzilion lines of code(like loading plugins, going trough preExecute, preExecute in transaction, execute, post execute in transaction, post execute). And this is only way described in Commerce SDK how to get that information and I dont even need assets them selves, just: BlobUid so I can generate proper URLs against Amazon.

 

So what I can do to get them faster is write my own SQL, but I dont like that, what instead i did is following:

var filter = FilterElement.EqualElement(FolderElementEntity.PrimaryKeyName, asset.AssetKey);
var metaClass = DataContext.Current.GetMetaClass(FolderElementEntity.ClassName);

var metaObject = MetaObject.List<MetaObject>(metaClass, new[] {filter});

var amazonUniqueIdentifierWeNeed = metaObject[0].Properties["BlobUid"].Value;

  

And it works much much faster, probably because that this way gazzilion lines of code are skiped.

The question is, is there and what are drawbacks if I'm getting BlobUid this way?

  

#59329
Jun 01, 2012 8:12
Vote:
 

You are correct when using EntityManager, data fetching can take longer.  This is explained in detail in the following link http://sdk.episerver.com/commerce/1.1.2/Content/Developers%20Guide/Architecture/BusinessFoundation/Working%20with%20Entity%20Objects.htm

 

You can modify which handlers and plugins you want to run for each class and operation in baf.data.manager.config file in your configs folder.

<?xml version="1.0"?>
<businessManager>
  <handlers>
    <add metaClass="Folder" method="*" type="Mediachase.Commerce.Assets.FolderRequestHandler, Mediachase.Commerce" />
    <add metaClass="FolderElement" method="*" type="Mediachase.Commerce.Assets.FolderElementRequestHandler, Mediachase.Commerce" />
    <add metaClass="Contact" method="*" type="Mediachase.Commerce.Customers.Handlers.ContactRequestHandler, Mediachase.Commerce" />
    <add metaClass="Organization" method="*" type="Mediachase.Commerce.Customers.Handlers.OrganizationRequestHandler, Mediachase.Commerce" />
    <add metaClass="Address" method="*" type="Mediachase.Commerce.Customers.Handlers.CustomerRequestHandlerBase, Mediachase.Commerce" />
    <add metaClass="CreditCard" method="*" type="Mediachase.Commerce.Customers.Handlers.CreditCardRequestHandler, Mediachase.Commerce" />
    <add metaClass="CustomizationItem" method="*" type="Mediachase.Commerce.Customization.CustomizationItemRequestHandler, Mediachase.Commerce" />
    <add metaClass="CustomizationItemArgument" method="*" type="Mediachase.Commerce.Customization.CustomizationItemArgumentRequestHandler, Mediachase.Commerce" />
    <add metaClass="CustomPage" method="*" type="Mediachase.Commerce.Customization.CustomPageRequestHandler, Mediachase.Commerce" />
  </handlers>
  <plugins>
    <add method="*" metaClass="Contact" eventStage="PreMainOperation" type="Mediachase.Commerce.Customers.Plugins.AutoInstallMetaDataModule, Mediachase.Commerce" />
    <add method="*" metaClass="Organization" eventStage="PreMainOperation" type="Mediachase.Commerce.Customers.Plugins.AutoInstallMetaDataModule, Mediachase.Commerce" />
    <add method="*" metaClass="Address" eventStage="PreMainOperation" type="Mediachase.Commerce.Customers.Plugins.AutoInstallMetaDataModule, Mediachase.Commerce" />
    <add method="*" metaClass="CreditCard" eventStage="PreMainOperation" type="Mediachase.Commerce.Customers.Plugins.AutoInstallMetaDataModule, Mediachase.Commerce" />
    <add method="*" metaClass="Folder" eventStage="PreMainOperation" type="Mediachase.Commerce.Assets.Plugins.AutoInstallMetaDataModule, Mediachase.Commerce" />
    <add method="*" metaClass="FolderElement" eventStage="PreMainOperation" type="Mediachase.Commerce.Assets.Plugins.AutoInstallMetaDataModule, Mediachase.Commerce" />
    <add method="*" metaClass="CustomizationItem" eventStage="PreMainOperation" type="Mediachase.Commerce.Customization.Plugins.AutoInstallMetaDataModule, Mediachase.Commerce" />
    <add method="*" metaClass="CustomizationItemArgument" eventStage="PreMainOperation" type="Mediachase.Commerce.Customization.Plugins.AutoInstallMetaDataModule, Mediachase.Commerce" />
    <add method="*" metaClass="CustomPage" eventStage="PreMainOperation" type="Mediachase.Commerce.Customization.Plugins.AutoInstallMetaDataModule, Mediachase.Commerce" />
    <add method="List" metaClass="CustomPage" eventStage="PostMainOperationInsideTranasaction" type="Mediachase.Commerce.Customization.Plugins.CustomPageNormalizationPlugin, Mediachase.Commerce" />
    <add method="Create" metaClass="*" eventStage="PreMainOperation" type="Mediachase.Commerce.Core.RecentReferenceHistory.RecentReferenceDetectPlugin, Mediachase.Commerce" />
    <add method="Update" metaClass="*" eventStage="PreMainOperation" type="Mediachase.Commerce.Core.RecentReferenceHistory.RecentReferenceDetectPlugin, Mediachase.Commerce" />
    <add method="Delete" metaClass="*" eventStage="PreMainOperation" type="Mediachase.Commerce.Core.RecentReferenceHistory.RecentReferenceCleanupPlugin, Mediachase.Commerce" />
    <add method="Delete" metaClass="*" eventStage="PreMainOperationInsideTranasaction" type="Mediachase.Commerce.Core.CleanupBridgeElementPlugin, Mediachase.Commerce" />
  </plugins>
</businessManager>

    You could disbale events on the list operation or use a method like you are doing.  There is also a way to just do one request by adding multiple keys in one request like below.

OrBlockFilterElement assetFilters = new OrBlockFilterElement();
			foreach (int key in assets)
				assetFilters.ChildElements.Add(new FilterElement("FolderElementId", FilterElementType.Equal, key));
			
			var folderElements = EntityManager.List<FolderElementEntity>(FolderElementEntity.ClassName, new FilterElement[] { assetFilters });

    

 

 

#59387
Jun 05, 2012 6:09
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.