Optimizing ESHOPMAN Admin API: Enhancing Translation Batch Performance

Optimizing ESHOPMAN Admin API: Enhancing Translation Batch Performance

At Move My Store, we're dedicated to sharing insights that empower the ESHOPMAN community. ESHOPMAN, as a headless commerce platform deeply integrated with HubSpot, relies on efficient data processing to manage storefront content, product variants, and more. The ESHOPMAN Admin API, built on Node.js/TypeScript, is the backbone for managing your store's operations, including critical tasks like updating translations for your HubSpot CMS-powered storefronts.

Recently, an important optimization was identified and implemented within the ESHOPMAN Admin API, specifically targeting the batch processing of translations. This enhancement significantly improves the performance and scalability of handling large volumes of translated content, ensuring a smoother experience for merchants and developers alike.

The Challenge: Inefficient ID Matching in Translation Batches

The ESHOPMAN Admin API provides an endpoint, /admin/translations/batch, designed to efficiently create and update multiple translations simultaneously. After the core workflow for processing these translations completes, the system needs to categorize the affected translations back into 'created' and 'updated' lists for the API response.

The original implementation for this categorization involved an inefficient approach. For every re-fetched translation, the system would scan through the entire list of 'created' or 'updated' IDs from the workflow result. This method, often referred to as 'quadratic complexity' (O(translations × result)), meant that as the number of translations in a batch increased, the processing time would grow disproportionately, leading to potential slowdowns, especially for large-scale storefronts with extensive multilingual content.

Consider the following original code snippet:

const created = translations.filter((t) => result.created.some((r) => r.id === t.id))
const updated = translations.filter((t) => result.updated.some((r) => r.id === t.id))

Here, for each translation t in the translations array, the .some() method iterates through the entire result.created (or result.updated) array. If you have 1000 translations and 500 created results, this could mean up to 500,000 comparisons just for the 'created' list, which is highly inefficient.

The ESHOPMAN Solution: Leveraging Set Data Structures for Linear Performance

The good news is that the ESHOPMAN platform's Node.js/TypeScript foundation provides powerful data structures to tackle such performance bottlenecks. The fix implemented for this issue is elegant and leverages a pattern already present within the ESHOPMAN codebase: using JavaScript's Set object for efficient ID matching.

A Set is a collection of unique values, and crucially, checking for the presence of an item in a Set (using Set.has()) is an extremely fast, nearly constant-time operation (O(1)). By first converting the arrays of 'created' and 'updated' IDs into Sets, the subsequent filtering operations become significantly more efficient.

Here's the optimized code:

const createdIds = new Set(result.created.map((r) => r.id))
const updatedIds = new Set(result.updated.map((r) => r.id))

const created = translations.filter((t) => createdIds.has(t.id))
const updated = translations.filter((t) => updatedIds.has(t.id))

With this change, the process of categorizing translations becomes linear (O(translations + result)). Instead of hundreds of thousands of comparisons, the system now performs a much smaller, fixed number of operations per translation, regardless of the size of the 'created' or 'updated' result arrays.

Impact and Benefits for ESHOPMAN Users

This internal optimization, while not changing the external API, has a direct positive impact on the ESHOPMAN experience:

  • Faster Translation Updates: Merchants managing extensive multilingual content for their HubSpot CMS storefronts will notice improved responsiveness when performing batch translation updates via the Admin API.
  • Enhanced Scalability: The platform can now handle larger translation batches more efficiently, supporting the growth of stores with vast product catalogs and international reach.
  • Robust Admin API: This optimization contributes to the overall stability and performance of the ESHOPMAN Admin API, providing a more reliable foundation for custom development and integrations.
  • Leveraging Node.js Best Practices: It showcases ESHOPMAN's commitment to utilizing Node.js/TypeScript best practices for high-performance headless commerce.

At Move My Store, we believe that such technical refinements are crucial for a leading headless commerce platform like ESHOPMAN. They ensure that your storefront management within HubSpot remains seamless, fast, and scalable, supporting your e-commerce ambitions.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools