on 2021 Aug 18 9:44 AM
Hi all,
I am wondering what would be the better option for disabling SearchRestrictions temporarily - running the code within threadContextService.executeInContext or sessionService.executeInLocalView?
If I take a look into the platform core classes, always sessionService.executeInLocalView is used (see below).
public List<OrderModel> getRejectedOrders(final UserModel user)
{
return getSessionService().executeInLocalView(new SessionExecutionBody()
{
@Override
public List<OrderModel> execute()
{
getSearchRestrictionService().disableSearchRestrictions();
return getB2bOrderDao().findRejectedOrders(user);
}
});
}
In some of our custom sources, I see an approach using the ThreadContext (see below).
public ProductModel getProductWithoutSearchRestrictions(final CatalogVersionModel catalogVersion, final String code) {
return threadContextService.executeInContext(() ->
{
searchRestrictionService.disableSearchRestrictions();
final ProductModel productWithoutRestrictions = super.getProductForCode(catalogVersion, code);
searchRestrictionService.enableSearchRestrictions();
return productWithoutRestrictions;
}
);
}
Does have anyone a suggestion?
Best regards,
Torsten
Request clarification before answering.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.