cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Difference between ThreadContextService - executeInContext and SessionService - executeInLocalView

torsten_lorenz
Explorer
498

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

Accepted Solutions (0)

Answers (0)