Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. The Developer Center continues to support Commerce 6.13.0 through 7.4.1.Visit new site

Load tuners

Load tuners

Retrieving data from persistent storage is expensive from a performance perspective. Catalog objects (products, SKUs, categories) have large object graphs and in many situations, you don't want to load all the data associated with a particular object. For example, when retrieving a list of products for a shopper who is browsing a store's catalog, you don't want to load each product's merchandizing associations, since that information isn't displayed in this context and it would increase page load time. However, when the shopper clicks a product to view its details, you need to load that product's merchandizing associations in order to display cross-sells, up-sells, accessories, etc.

Load tuners provide coarse-grained control of what data is retrieved when loading catalog objects. Many out-of-the-box load tuners are defined in the core's ep-core/src/main/resources/spring/models/domainModel.xml. Additional application-specific load tuners are defined in the Batch Server's ep-batch/src/main/resources/spring/service/serviceBatch.xml and Search Server's ep-search/src/main/resources/spring/service/serviceSearch.xml.

Configuring load tuners

A load tuner consists of a set of boolean properties that specify whether to load a particular type of data when loading objects of the load tuner type. If a property value is true, the data is loaded. If it is false or if the property is not included in the bean definition, the data is not loaded.

For example, the following are two bean definitions for product type load tuners. PRODUCT_TYPE_LOAD_TUNER_ALL loads product types with all their attributes and SKU options. PRODUCT_TYPE_LOAD_TUNER_ATTRIBUTES loads product types with only their attributes.

<bean id="PRODUCT_TYPE_LOAD_TUNER_ALL"
	class="com.elasticpath.domain.catalog.impl.ProductTypeLoadTunerImpl"
	scope="singleton" parent="epDomain">
	<property name="loadingAttributes">
		<value>true</value>
	</property>
	<property name="loadingSkuOptions">
		<value>true</value>
	</property>
</bean>

<bean id="PRODUCT_TYPE_LOAD_TUNER_ATTRIBUTES"
	class="com.elasticpath.domain.catalog.impl.ProductTypeLoadTunerImpl"
	scope="singleton" parent="epDomain">
	<property name="loadingAttributes">
		<value>true</value>
	</property>
	<property name="loadingSkuOptions">
		<value>false</value>
	</property>
</bean>

Troubleshooting load tuner issues

Load tuners are wired to services at both the domain layer (ep-batch/src/main/resources/spring/service/serviceBatch.xml and the persistence layer (ep-core/src/main/resources/spring/dataaccess/dao.xml). If your code is using any of these services to retrieve catalog objects and you are finding that some data you need is missing, or if too much of the object graph is being loaded and is causing performance problems, check the method implementation to see which load tuner is being used.

For example, in ProductSkuServiceImpl, the findByProductUid(long productUid) method is implemented as follows:

               core/ep-core/src/main/java/com/elasticpath/service/catalog/impl/ProductSkuServiceImpl.java
public List<ProductSku> findByProductUid(final long productUid) {
	fetchPlanHelper.configureProductSkuFetchPlan(this.productSkuLoadTunerMinimal);
	List<ProductSku> result = getPersistenceEngine().retrieveByNamedQuery("PRODUCTSKU_SELECT_BY_PRODUCT_UID", new Long(productUid));
	fetchPlanHelper.clearFetchPlan();
	return result;
}
            

In this case, the productSkuLoadTunerMinimal is used. This load tuner is defined in core's domainModel.xml as follows:

<bean id="PRODUCT_SKU_LOAD_TUNER_MINIMAL"
	class="com.elasticpath.domain.catalog.impl.ProductSkuLoadTunerImpl"
	scope="singleton" parent="epDomain">
	<property name="loadingAttributeValue">
		<value>false</value>
	</property>
	<property name="loadingInventory">
		<value>false</value>
	</property>
	<property name="loadingOptionValue">
		<value>true</value>
	</property>
	<property name="loadingProduct">
		<value>false</value>
	</property>
	<property name="loadingDigitalAsset">
		<value>false</value>
	</property>
</bean>

So, when findByProductUid() is called, it loads the corresponding product SKUs with only their SKU option values. Attribute values and inventory data are not included.