This is a suggestion for the Configured Commerce (B2B) Product Engineering team.
For the V2 Services that inherit from ServiceV2Base (Such as the V2 Product Service) we can improve performance for scenarios where we only read data but are not expected to update anything.
As things stand currently, in ServiceV2Base we begin a transaction (if not already active) and all subsequent activity in the handler chain is carried out as part of a transaction. Then changes are saved and the transaction closed.
The Handler chain may take a long time to execute especially if calls to external 3rd Party services are involved. This would cause the transaction to remain open for a long time and not serve any real benefit for a read-only scenario.
Another problem is that for a use case that is expected to only read data, a developer may inadvertently update data.
We can avoid these issues for read-only scenarios by including an optional parameter on the ExecuteHandlerChain
implementation.
*** For the following discussion, I am not able to attach the .CS or .ZIP files here due to attachment restrictions. Please indicate how I can send the attachment ***
I have attached a suggestion for implementing the same (Note: Due to the large overall size of the solution, it does not compline on my development machine. I do not guarantee the suggested changes and should be merely treated as inputs). All changes are marked with "RK changes start" and "RK changes end".
The files changed are: ServiceV2Base, IUnitOfWork, UnitOfWork, IDataProvider and EntityFrameworkDataProvider
.
However, if we chose to simply ignore the changes instead of throwing an exception (not a robust implementation), we will only need to change ServiceV2Base.
There is a related support ticket #1122215 for this feedback. The ZIP file is attached to that ticket. https://support.optimizely.com/hc/en-us/requests/1122215
https://episerver.zendesk.com/attachments/token/XZK249yDN5h5XXFWjJGtkgKfy/?name=ReadOnlyAPICall+Suggestions.zip