[POS Orders] Performance Improvements Discussion #14892
Draft
+167
−34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
⚙️ Context
This Draft PR is not intended to be merged — it serves as a space for collaboration to find the best long-term solution.
During testing, we noticed that the orders cache was not displaying results immediately. After investigation, we found that mapping the order models from the backend to the corresponding view models in the UI was taking a considerable amount of time:
replaceOrders: buildItemsMap() took 5955ms for 25 orders🔍 Findings
The main bottleneck was identified in
WooPosFormatPrice, where site settings were being fetched on every single call.After introducing currency-code caching, the mapping time improved significantly:
replaceOrders: buildItemsMap() took 2568ms for 25 orders💡 Discussion
Caching the currency code introduces a potential downside — if the site settings change (for example, switching to another site), the cached value could become outdated.
However, since
WooPosFormatPriceis not a singleton, it will be deallocated together with its parent object, so the cache should remain consistent within the object’s lifecycle.An alternative could be to inject the currency code directly, though that comes with its own disadvantages (e.g., tighter coupling and less flexibility).
❓ Questions
@kidinov — what do you think about this caching approach?
Do you see other opportunities to reduce the mapping time based on our measurements?