This project is read-only.

Are drivers supposed to be executed if the shape is disabled in the

Topics: Core, General, Troubleshooting
Oct 12, 2012 at 8:32 PM

Hi, i'm doing some performance optimizations in my Orchard and I'm running into the following issue:

I have a detail page that displays 1 content item. This content item has a favorite part and like part attached to it. 

When I turn both parts off in the, mini profiler is telling me the queries are still being executed (in the favoritepartdriver and the likepartdriver). I added a breakpoint and it executes the driver indeed. 

Is that standard behavior? Is there a way to prevent this from happening?



Oct 12, 2012 at 9:33 PM
Edited Oct 12, 2012 at 9:34 PM

Yes, this is standard behavior: placement acts on the *results* of the drivers, not on the parts.

This is why the actual shape creation happens in a Lambda. The Lambda will only get executed if the shape really is going to be rendered. Maybe that's where you need to move your code.

What problem is that causing you exactly?

Oct 12, 2012 at 11:00 PM

That's also why you need to place the SQL statements inside the lambda of the Shape result, and not outside of it.

Oct 13, 2012 at 10:02 AM

I see what you guys are saying, not sure on how to implement this though. @bertrand: the problem is that my qeuries to render the part are currently executed, eventhough I have no use for the shape. It's a performance thing (and just trying to understand what's going on here).

My favoritepart driver is displayed below, queries are in the BuildVoteUpDown method. Are you saying they won't get executed if I put them in the lambda, unless actually displayed? I'm just trying to get a better understanding of how this works. Also @sebastien: related to this I posted a question in the discussion for the Voting module. If you get a change to look it over...

var displayPart = BuildVoteUpDown(part);
	return Combined( 
		ContentShape("Parts_Favorite",() => shapeHelper.Parts_Favorite(displayPart))

Thanks for the help,

Oct 13, 2012 at 11:17 AM
Edited Oct 13, 2012 at 11:21 AM

The BuildVoteUpDown() function will always be called. "shapeHelper.Parts_Favorite(displayPart)" will however not be called if the Shape is hidden. So, if you place "var displayPart = BuildVoteUpDown(part);" inside the lambda you'll get a performance increase, assuming the function does something that takes at least some time :)

	return Combined( 
		ContentShape("Parts_Favorite",() => {
			var displayPart = BuildVoteUpDown(part);
			return shapeHelper.Parts_Favorite(displayPart);

Oct 13, 2012 at 11:38 AM

this works, so that's one down. Very good to know.