I have a helper function that retrieves information from a view programmatically, processes the info and returns information to be added to a node.

If I hook nodeapi 'view' and run the function on the node, it works without any trouble. However, if I run the function on 'load' it times out and returns nothing. Originally, it caused php to exceed the memory limit of 32mb. After raising the limit, it now just times out to a white screen. I have traced this to happen when build() is called on the view.

Viewing the same view's page display is fine, and calling build() on it outside of nodeapi 'load' is fine.

Any ideas on what would be causing this?

Thank you in advance.

Comments

merlinofchaos’s picture

Have you checked to see if you're creating an infinite loop?

CPyle’s picture

It does this when $view->build() is called even when I comment out everything else in the function except for loading the view and building it. The only thing I could think of would be if views at some point calls node_load on the original node when it is building the query, which would cause an infinite loop. I could try statically caching the view object and checking for its status before executing build() I suppose?

That might not solve the end problem but it may identify an infinite loop somewhere.

Update: I tried making the view object itself static. This does indeed fix an infinite loop wherein build() triggers a 'load' operation on the original object. I've made a workaround to only go through with the processing if the views object has not yet been created, and I can now load my node.

If there's a better way to get around this, or if you think I might be breaking something else by doing this, let me know, otherwise I'll set this to resolved after more testing.

CPyle’s picture

Upon finding that views handles it's own static object cache, I'm going to try a slightly different approach. Same general idea.

Update: Well, checking the $view->built variable seemed not to work as it appeared to be reset after reloading the object from cache. Reverted to previous method.

merlinofchaos’s picture

Status: Active » Fixed

Did you determine where the load operation is being triggered? It seems likely it would be an argument validator or something along those lines. If this is the case, I would say that your call needs to be responsible to guard against loops (since it isn't a normal operation to build a view during node_load()). You can easily do this:

static $guard = FALSE;

if (!$guard) {
  $guard = TRUE;
  $view->build();
  $guard = FALSE;
}
else {
  // looped.
}

Marking as fixed; I don't believe this is a problem with Views in particular.

CPyle’s picture

Yes, that is more or less what I ended up doing. So far it's had no negative effects on anything else that I've seen.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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