Maintaining and cleaning up accumulated data in large-scale SAP Commerce Cloud projects is crucial for ensuring high performance and system scalability. Over time, data growth from customer transactions, product catalogs, and system logs can slow operations if left unmanaged. This data accumulation will lead to lower performance, higher storage costs, and more wasted time by developers and support specialists. Hence, keeping a clean SAP hybris instance will save you money, so addressing it should be a no-brainer for any SAP Commerce team.

This article outlines best practices and key cleanup strategies to optimize your SAP Commerce Cloud environments.

The platform provides two ways to clean up unused data:

  • Maintenance Framework: This older approach requires significant implementation effort. Developers must create custom strategies to fetch and process items and write code to define the logic for data cleanup.
  • Data Retention Framework: A newer, more streamlined solution that addresses most use cases through configuration alone. It enables you to define retention rules specifying the logic for retrieving and removing items using queries and standard removal actions. Additionally, it supports injecting custom logic for processing items when needed.

The following sections will focus on examples utilizing the Data Retention Framework.

Data Maintenance

Key Cleanup Areas and Strategies

Cronjobs

Cronjobs automate essential tasks but, over time, can bloat the system. Regularly clearing outdated cronjob records ensures smooth operations. The most common types of jobs include:

  • Impex Import/Export
  • Catalog Synchronization
  • Solr Jobs

To clean up these cronjob instances, you can set up a retention job using the ImpEx below:

Copy to Clipboard

*NOTE: Another method for deleting these cronjobs is to use the CleanupCronJobStrategy from the legacy Maintenance Framework. However, this approach requires customization to fine-tune the selection of cronjobs it handles.

Cronjob Logs

As time passes, cronjob logs will also accumulate. To clean up old cronjob log files, you must set up a cronjob and a trigger specifically for log deletion.

It’s important to note that the platform does not automatically remove old log files.

Copy to Clipboard

If you have cronjobs that run frequently, it’s recommended that you schedule log file cleanups more often. This helps prevent an excessive accumulation of log files that need to be deleted later.

Cronjob Histories

Like cronjob logs, cronjob histories can accumulate for jobs that run very frequently. SAP Commerce comes with cronJobHistoryRetentionCronJob, which limits the number of CronJobHistory entries per cronjob. This cronjob is enabled by default; you just need to make sure it’s enabled and set up a trigger.

Impex Import/Export Media

Each ImpEx import or export results in the creation of at least one ImpexMedia object. These media files remain in the system even after the associated ImpEx jobs are deleted, as the platform does not automatically remove them. A retention job can be created to clean up old media.

Copy to Clipboard

Saved Values

The Backoffice utilizes Saved Values to monitor changes made to items by business users, displayed under “Last Changes” in the Administration tab. If your project has been running for an extended period or has undergone multiple upgrades, your database has likely accumulated millions of SavedValues and SavedValueEntry records.

You can configure how many entries per item are stored using the following property:

Copy to Clipboard

The very last change (if available) is always displayed. Also, to free up space in the database, we can set up retention rules to delete old entries:

Copy to Clipboard

To make it more convenient, we can create an instance of CompositeCronJob to have both cronjobs run in the desired order by having to run only one cronjob.

Copy to Clipboard

HTTP Sessions

For Accelerator-based storefronts, HTTP Sessions can be stored in the database using the HTTP Session Failover feature. To prevent performance issues, it’s critical to clean up obsolete sessions. You can accomplish this by setting up another retention rule:

Copy to Clipboard

Transactional Data

This is the data that SAP hybris creates when customers use the storefront. To speed things up, some of this unused data can be removed. Let’s examine it in more detail.

Carts

For removing old abandoned carts, SAP Commerce provides the following cronjob Out of the Box: Removing Old Carts with Cronjob

We only need to configure it as we need it, as it’s pretty straightforward.

Business Processes

Most user actions in the Accelerator initiate Business Processes, such as resetting passwords, placing orders, and managing order fulfillment. These processes accumulate over time and must be regularly removed to maintain system efficiency.

Copy to Clipboard

If you have customised business processes, clean up any related data. For instance, EmailMessages are automatically removed at the end of a business process if sent successfully. However, those that fail to send will remain in the database and should be addressed during regular maintenance.

Type System Cleanup

To maintain an optimized SAP Commerce Cloud system, cleaning up unnecessary data and configurations in the type system is essential for ensuring optimal performance and database health. The type system can accumulate unused or redundant entities over time, such as Orphan Types and Orphan Attributes. This section will cover how to identify and remove these orphaned elements from your SAP Commerce Cloud system.

Orphan Types

Orphan types refer to records in the database that no longer have valid references. These typically occur when a parent entity is deleted from the items.xml, but the associated child entities remain in the database. Orphaned records can clutter your database, slowing query performance and increasing storage costs.

The Hybris Administration Console (HAC) is the primary tool for identifying and removing orphan types in SAP Commerce Cloud. According to SAP’s recommendations, orphan types should be manually cleaned using the HAC. This can be achieve from Maintenance -> Cleanup -> Type system.

Orphaned types in the hybris console

Orphan Attributes

In addition to orphan types, another common issue is Orphan Attributes. These attributes are typically left behind after code refactoring or removing unused features. While they no longer serve a purpose in the system, they still exist in the database, potentially confusing data model queries and impacting performance.

The recommended approach for removing orphan attributes is to run Impex scripts that explicitly remove them from the database. However, it is important to note that orphan attributes can only be removed from the original item type where they were defined. The Impex script will not work on subclassed or extended item types.

For example, the following Impex script removes the orphaned attribute defaultPaymentMode from the BaseStore itemtype:

Copy to Clipboard

Generic Audit

The Generic Audit feature records all persistence actions, such as creating, modifying, and deleting specified items. It maintains a change log that tracks how an item evolves. However, the rapid generation of this data can quickly accumulate, potentially impacting the performance of both your database and overall solution.

By default, it is enabled for a wide range of types. Therefore, the recommendation is to carefully review and consider turning off any type you don’t need for the Production Environment. You can turn on/off the auditing of a type by setting the following property for a specific typecode:

Copy to Clipboard

Boost your SAP Commerce Performance

Regular data cleanup maintains SAP Commerce Cloud’s performance and scalability. Implementing the strategies mentioned above ensures your system runs efficiently and remains prepared for future growth. If you need a hand with the clean up and performance of your SAP Commerce Solution, you can also reach out to us through our SAP hybris Development Services, and the E-Turia engineers will fine-tune your solution to maximize its potential.

ETuria square logo