It is a relatively expensive function with a db query and it can get called multiple times on a page load. The approach I've taken with this patch is to only statically cache if module and nid are known and the other function args are defaults. If they are not defaults, I don't cache. This hits the vast majority of cases and avoids redundant queries.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chromeyellow’s picture

A good patch, but the underlying issue still may be the one noted at http://drupal.org/node/74016#comment-167964 ...

Briefly, links_load_links_for_node only needs to be called once, during the 'load' component on links_related_nodeapi. That loads the link info into the node object, after which it is available like everything else in a $node. However, as it stands the module persists in loading link data everytime it's needed, rather than grabbing the data from the node object.

Sys and I traded notes on this but it fell off the radar, buried in a comment in a 4.7 bug (that may have been a side-effect of all those unnecessary queries). Also, I had only had time to specifically analyse the links_related side of things.

At any rate, this patch would be useful failsafe - but the underlying code error still needs tending...

robphillips’s picture

Component: Code: API » Code: links.module

The patch above failed for the latest release for me, attached is just an updated patch that should update successfully.

robphillips’s picture

FileSize
3.24 KB

Attaching patch...

robphillips’s picture

FileSize
3.34 KB

Here is an updated patch which prevents a form error when updating an existing link.