If a viewfield field uses a token for an argument (in my case [term-id]) then the evaluation of token values results in a recursive call to drupal_render which results in an extra view execution as follows:

1. render node
2. theme viewfield field
3. evaluate token values
3.1 render node
3.2 theme viewfield field
3.3 invoke views_embed_view without token arguments ** - this shouldn't happen
3.4 return token values
4. invoke views_embed_view with token arguments

If the view construction is expensive (e.g. view with remote service query plugin) then the node takes almost twice as long to render as it should do.

Below is a patch which wraps the _viewfield_get_view_args call in a status flag to prevent the recursive call. This change also means that the condition for limiting display to 2 levels of viewfield can be correctly written as count($_viewfield_stack) < 2 rather than count($_viewfield_stack) <= 2 as the viewfield stack no longer includes the erroneous argument evaluation call.

Andy

Comments

chaps2’s picture

Status: Active » Needs review
StatusFileSize
new1.33 KB

Here's the patch...

sun’s picture

Status: Needs review » Fixed
StatusFileSize
new3.08 KB

I think we just want to avoid to process the same node more than once.

Thanks for reporting, reviewing, and testing! Committed attached patch.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

codycraven’s picture

Version: 6.x-1.x-dev » 6.x-1.1
Status: Closed (fixed) » Needs work

After upgrading to 1.1 I am still having this problem. I have a hook_views_pre_build() that is ran twice, verified by calling a dpm().

The first run occurs before the dpm is output and the second is after. So when first viewing the page using the viewfield there is a single dpm() but upon refresh there are two.

keithm’s picture

Version: 6.x-1.1 » 6.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new989 bytes

@codycraven: We've been forced to focus development on the 6.x-2.x branch, which we're trying to get ready for release. If you're willing to upgrade, please try this patch. It pushes the current node onto the stack before processing arguments, which may help your problem.

codycraven’s picture

Status: Needs review » Closed (fixed)

Thanks Keith,

Looks like the problem was with a custom formatter on the site. So the view stack does correctly prevent the logic from running twice.

keithm’s picture

Status: Closed (fixed) » Needs review

I would like to get #5 committed before releasing 6.x-2.0. This is the same logic used in the 7.x-2.x branch.

sun’s picture

Status: Needs review » Reviewed & tested by the community
keithm’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.