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
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | view-run-twice-535494-5.patch | 989 bytes | keithm |
| #2 | viewfield-HEAD.recursion.2.patch | 3.08 KB | sun |
| #1 | viewfield-535494.patch | 1.33 KB | chaps2 |
Comments
Comment #1
chaps2 commentedHere's the patch...
Comment #2
sunI 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.
Comment #4
codycraven commentedAfter 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.
Comment #5
keithm commented@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.
Comment #6
codycraven commentedThanks 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.
Comment #7
keithm commentedI 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.
Comment #8
sunComment #9
keithm commentedCommitted: http://drupalcode.org/project/viewfield.git/commit/00142ae.